Bootstrap only for mixins/placeholders - with semantic classes

不问归期 提交于 2019-12-10 15:40:02

问题


I'm thinking about using only semantic classes in my HTML, while still using Bootstrap's classes styles inside the semantic classes.

For example:

mixins:

.newsItem {
    @include span4;
}

or placeholders/extends:

.newsItem {
    extend span4;
}

Is it possible at all? and do you see any reason why that's not recommended ? Thanks.


回答1:


@include span4; and @extend .span4; won't work because:

  • In the first one, there isn't any mixins called that way in bootstrap.
  • In the second one, there isn't any selector called span4, the selectors are being generated with mixins like grid-core-span-x.

There are built mixins for that purpose: makeRow() and makeColumn().

In your case, if you want to use a span4 in your .newsItem div, you have to put this in your SASS:

.newsItem {
  @include makeColumn(4);
}

The code from those mixins is simple.

@mixin makeRow() {
  margin-left: $gridGutterWidth * -1;
  @include clearfix();
}

@mixin makeColumn($columns: 1, $offset: 0) {
  float: left;
  margin-left: ($gridColumnWidth * $offset) + ($gridGutterWidth * ($offset - 1)) + ($gridGutterWidth * 2);
  width: ($gridColumnWidth * $columns) + ($gridGutterWidth * ($columns - 1));
}

This mixins have downsides. I don't use them since the responsive grid won't be used in your semantics class. Why? Because if you look at the files that provide bootstrap a responsive (for instance, _responsive-767px-max.scss), only the spanX classes converts to a 100% width. The code:

@media (max-width: 767px) { 
     /* ... */

     [class*="span"],
     .uneditable-input[class*="span"], 
     .row-fluid [class*="span"] {
         float: none;
         display: block;
         width: 100%;
         margin-left: 0;
         @include box-sizing(border-box);

      /* ... */
}


来源:https://stackoverflow.com/questions/16511875/bootstrap-only-for-mixins-placeholders-with-semantic-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!