Bootstrap3 is it valid for 1 row to have infinity columns?

假如想象 提交于 2019-12-06 11:18:42

问题


Using Bootstrap3 and the grid system. The default settings are 12 columns in the grid system.

Is there any adverse outcomes to writing html similar to:

<div class="row">
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
    <div class="col-md-12">...</div>
</div>

or

<div class="row">
    <div class="col-md-4">...</div>
    <div class="col-md-4 hidden">...</div>
    <div class="col-md-4">...</div>
    <div class="col-md-4 hidden">...</div>
    <div class="col-md-4">...</div>
    <div class="col-md-4 hidden">...</div>
    <div class="col-md-4">...</div>
    <div class="col-md-4 hidden">...</div>
</div>

回答1:


This is absolutely valid and documented markup for bootstrap. Have a look at my answer explaining this idea in depth: Bootstrap 3 and .col-xs-* -- Do you not need rows of 12 units? (includes pictures for a visual representation).

From the documentation:

<!-- Stack the columns on mobile by making one full-width and the other half-width -->
<div class="row">
  <div class="col-xs-12 col-md-8">.col-xs-12 .col-md-8</div>
  <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>

<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<div class="row">
  <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
  <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
  <div class="col-xs-6 col-md-4">.col-xs-6 .col-md-4</div>
</div>

<!-- Columns are always 50% wide, on mobile and desktop -->
<div class="row">
  <div class="col-xs-6">.col-xs-6</div>
  <div class="col-xs-6">.col-xs-6</div>
</div>

If you look at the second example in the code, there are 3 columns, and the xs breakpoint has the value 6 for all columns. The sum of those columns being 18 (ie > 12).

This allows you to use the same markup for different row breaks on different breakpoints. The simplified idea is that you don't need to have different markup templates for different viewports. The actual .rows are guidelines, not concrete implementations that should only allow for columns equal to or less than 12.



来源:https://stackoverflow.com/questions/23014782/bootstrap3-is-it-valid-for-1-row-to-have-infinity-columns

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