I don't understand twitter bootstrap span and row

白昼怎懂夜的黑 提交于 2019-12-03 03:37:22

问题


I was a huge 960 grid system user, and I thought I would try out Twitter Bootstrap, but maybe it is a stupid question and you can laugh and down vote me but the fact is I don't understand the span and row.

So my problem is, when I create a container, and create spans inside of it, it does not fit next to each other correctly:

Like in 960gs if i write the following

<div class="container_12">
  <div class="grid_4"></div>
  <div class="grid_4"></div>
  <div class="grid_4"></div>
</div>

I get a perfect 3 column next to each other.

But I cannot achieve this with Twitter Bootstrap, no matter what I do, I always end up with disproportionate columns, so the columns do not fill the container as it supposed to, like with 960gs. If I place 3 columns, then the margin to the right is not correct, or it will not fit correctly in the container.

Boostrap example:

<div class="container">
    <div class="row">
        <div class="span4">
            <h2>Column one</h2>
            <p>
                Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
            </p>
        </div>  
        <div class="span4">
            <h2>Column one</h2>
            <p>
                Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
            </p>
        </div>  
        <div class="span4">
            <h2>Column one</h2>
            <p>
                Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
            </p>
        </div>  
    </div>  
</div>

So in the example above, I end up with disproportionate columns, there is no margin in the first column to the left. If I do this in 960gs with the grid classes it is perfect.

What is different about Twitter Bootstrap when compared to 960gs that is causing my issue?


回答1:


The reason:

  • container is 940px
  • row is 960px with a -20px margin
  • span4 300px with a 20px margin

when screen width is <=940px, the -20px from row and the 20px margin from span4 cancel each other out, that's why the first span4 has no left margin.

The 'twitter bootstrap' solution:

Add bootstrap-responsive.css and when the screen goes under 980px and beyond 768px:

container become 724px, row 744px and span4 228px, keeping a left margin on first span4.



来源:https://stackoverflow.com/questions/10962032/i-dont-understand-twitter-bootstrap-span-and-row

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