2

实施bootstrap 3网格的最佳做法是什么?有两个选项,通过html中的类和更少的mixins。Bootstrap 3 grid in less vs in html

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

<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> 

使用更少和引导混入和适当的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); 
      } 
     } 
     } 
    } 
} 

这听起来像是一个不错的想法,只需使用引导混合来定义结构,而不是使用LESS文件中已经定义的less文件中的元素结构。哪一个更容易维护?

+1

你的HTML的第二块是有点奇怪。虽然它看起来第一眼看起来好像你有一个div结束标记太多(在另一个测试段落之后),你真的有比结束标记更多的开始标记。 –

回答

5

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

使用并以更加语义的方式实现引导不会那么容易:

与电网问题实例有解决: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