简体   繁体   English

Bootstrap中.row的作用是什么?

[英]What is the purpose of .row in Bootstrap?

According to Bootstrap's documentation 根据Bootstrap的文档

Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) 行必须放在.container (固定宽度)或.container-fluid (全角)内

and

Use rows to create horizontal groups of columns. 使用行创建水平的列组。

Why is this necessary? 为什么这是必要的?

A .row can only occupy the maximum width of either .container or .container-fluid .row只能占据.container.container-fluid的最大宽度

Given that you have to close the .row it seems longer to write: 鉴于您必须关闭.row因此似乎要写更长的时间:

<div class="container">
    <div class="row">
        <div class="col-md-6">
            <h1>Column A</h1>
        </div>
        <div class="col-md-6">
            <h1>Column B</h1>
        </div>
    </div>

    <div class="row">
        <div class="col-md-6">
            <h1>Column C</h1>
        </div>
        <div class="col-md-6">
            <h1>Column D</h1>
        </div>
    </div>
</div>

Than this: 比这个:

<div class="container">
    <div class="col-md-6">
        <h1>Column A</h1>
    </div>
    <div class="col-md-6">
        <h1>Column B</h1>
    </div>
 </div>

<div class="container">
    <div class="col-md-6">
        <h1>Column C</h1>
    </div>
    <div class="col-md-6">
        <h1>Column D</h1>
    </div>
</div>

Container 容器

The container provide the width constraints on responsive widths. 容器在响应宽度上提供了宽度限制。 When the responsive sizes change, it's the container that changes. 当响应大小发生变化时,容器会发生变化。 Rows and columns are all percentage based so they don't need to change. 行和列均基于百分比,因此无需更改。 Note that there is a 15px margin on each side, canceled by rows. 请注意,每边有15px的边距,被行取消。


Rows 行数

Rows should always be in a container. 行应始终位于容器中。

The row provides the columns a place to live, ideally having columns that add up to 12. It also acts as a wrapper since all the columns float left, additional rows don't have overlaps when floats get weird. 该行为列提供了一个居住的地方,理想情况下,列的总数为12。它还可以作为包装器,因为所有列都向左浮动,当浮动变得怪异时,其他行不会重叠。

Rows also have a 15px negative margin on each side. 行的每边也有15px的负边距。 The div that makes up the row would normally be constrained inside of the container's padding, touching the edges of the pink area but not beyond. 组成该行的div通常会被限制在容器的填充内部,而不接触粉红色区域的边缘,但不能超出。 The 15px negative margins push the row out over top of the containers 15px padding, essentially negating it. 15px的负边距将行压到容器顶部15px的填充上方,从而使行基本无效。 Furthermore, rows ensure you that all of the divs inside of it appear on their own line, separated from the previous and the following rows. 此外,行确保您其中的所有div都显示在自己的行上,与上一行和下一行分开。


Columns

The columns now have 15px padding. 列现在具有15px的填充。 This padding means that the columns actually touch the edge of the row, which itself touches the edge of the container since the row has the negative margin, and the container has the positive padding. 这种填充意味着列实际上接触行的边缘,由于行具有负边距,而容器具有正的填充,列本身就接触容器的边缘。 But, the padding on the column pushes anything inside the column in to where it needs to be, and also provides the 30px gutter between columns. 但是,列上的填充将列内的任何内容推入所需的位置,并且在列之间提供了30px的装订线。 Never use a column outside of a row, it won't work. 切勿在行外使用列,否则将无法使用。


For more information, I suggest you to read this article . 有关更多信息,建议您阅读本文 It is really clear, and explain well how Bootstrap's grid system works. 很清楚,并且很好地解释了Bootstrap的网格系统如何工作。

The .row elements have a negative margin on both sides. .row元素两边的边距均为负。 All the columns have a padding taking care of the spacing, even the first and the last one (which is something we don't want) so the .row pulls them back to fix that. 所有列都有填充,以确保间距,即使是第一个和最后一个(我们也不想这样),因此.row将它们拉回以解决该问题。 Also, I think it makes more sense to have more rows in a container, instead of columns. 另外,我认为在容器中而不是列中包含更多行更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM