html - Bootstrap 3 网格在 less 与在 html 中的比较

标签 html twitter-bootstrap less twitter-bootstrap-3 grid-layout

实现 Bootstrap 3 网格的最佳实践是什么?有两种选择,通过 html 中的类和通过 less mixins。

在 html 和 bootstrap.css 中使用 bootstrap 类(这似乎是标准):

<div class="container">
    <div class="row">
        <div class="column-md-6 column-xs-8">
            <p>test</p>
        </div>
        <div class="column-md-6 column-xs-4">
            <div class="row">
                <div class="column-md-8 column-xs-6">
                    <p>Another test</p>
                </div>
                <div class="column-md-4 column-xs-6">
                    <p>Yet another test</p>
                </div>
            </div>
        </div>
    </div>
</div>

使用 LESS 和 bootstrap mixin 以及适当的 html 结构:

<div id="maincontent">
    <div id="maincontentarea">
       <div id="blogarticles">
          <p>test</p>
       </div>
       <div id="whatsnew">
          <div id="whatsnewarea">
             <div id="whatsnewheading">
                <p>Another test</p>
             <div>
             <div id="whatsnewlist">
               <p>Yet another test</p></div>
             <div>
          </div>
       </div>
    </div> 
 <div>

以及相应的 LESS:

#maincontent{
   .container();
   #maincontentarea{
      .make-row();
      #blogarticles{
         .make-md-column(6);
         .make-xs-column(8);
      }
      #whatsnew{
         .make-md-column(6);
         .make-xs-column(4);
         #whatsnewarea{
            .make-row();
            #whatsnewheading{
              .make-md-column(8);
            }
            #whatsnewlist{
              .make-xs-column(6);
            }
         }
      }
   }
}

简单地使用 bootstrap mixin 来定义结构的 .LESS 文件听起来是一个好主意,但这本质上并不复制已在 LESS 中定义的 less 文件中的元素结构。哪一个更易于维护?

最佳答案

我个人认为使用 Bootstrap 的类会给你一个可维护的结构。否则,您可能更喜欢更语义的解决方案。请注意,在我看来,您适当的 html 结构没有附加值,并且不是语义的。

以更语义化的方式使用和实现 Bootstrap 并不总是那么容易:

必须解决的网格问题示例:How can I create multiple rows using semantic markup in Bootstrap 3? 。另外Twitter's Bootstrap 3.x semantic mobile grid特别注意@Gravy(https://stackoverflow.com/a/18667955/1596547)的回答。

也很有趣:How to use sass to properly avoid embedding twitter bootstrap class names on HTML

关于html - Bootstrap 3 网格在 less 与在 html 中的比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20558285/

相关文章:

javascript - 重叠图像跨越 CSS 或 HTML 中的表格单元格边框

javascript - 如何根据数值通过数据属性进行搜索并获取最接近的值

html - 带有文本溢出省略号的流体宽度

css - WebStorm:LESS 未在 Mac 上编译

javascript - Less.js 主动缓存导入的 LESS 文件

less - 如何在 less like sass 的 !default 标签中创建默认变量

ruby-on-rails - HTML5 应用程序 list 未在 list 更改时清除缓存

html - 如何让并排放置的两个div居中

html - 如何更改 Bootstrap 的井颜色?

javascript - 如何获取 Bootstrap slider 的最小值和最大值输入