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