官术网_书友最值得收藏!

Offsetting

One neat feature of the grid system is how it allows you to create empty space within your row using columns. If you wanted to list the categories and sizes but, for some reason, you wanted to leave the space for Medium empty, in other grid systems you may need to add the empty elements to the markup to get the desired effect. Consider the given example:

<div class="container">
<h1>Our Print Sizes</h1>
<div class="row">
<div class="col-6 col-sm-3">
<h5>Small</h5>
<div class="row">
<div class="col-sm-4">6x5</div>
<div class="col-sm-4">8x10</div>
<div class="col-sm-4">11x17</div>
&lt;/div>
</div>
<div class="col-6 col-sm-3"></div>
<div class="col-6 col-sm-3">
<h5>Large</h5>
<div class="row">
<div class="col-sm-4">19x27</div>
<div class="col-sm-4">20x30</div>
<div class="col-md-4">22x28</div>
</div>
</div>
<div class="col-6 col-sm-3">
<h5>Extra Large</h5>
<div class="row">
<div class="col-md-4">24x36</div>
<div class="col-md-4">27x39</div>
<div class="col-md-4">27x40</div>
</div>
</div>
</div>
</div>

Observe the following screenshot:

Figure 2.13: Adding spacing between columns (example11.html)

While it has the desired effect, it is adding markup simply for the sake of layout, which isn't really what we want to do if we can avoid it. Bootstrap allows us to avoid it via the offset classes. The offset classes follow the same convention as the rest of the column classes, offset-*-*. Now, we can remove the empty layout elements and simply add the offset classes to the Large columns. Take a look at the following code:

<div class="col-6 col-sm-3">
<h5>Small</h5>
<div class="row">
<div class="col-sm-4">6x5</div>
<div class="col-sm-4">8x10</div>
<div class="col-sm-4">11x17</div>
</div>
</div>
<div class="col-6 col-offset-6 col-sm-3 offset-sm-3">
<h5>Large</h5>
<div class="row">
<div class="col-sm-4">19x27</div>
<div class="col-sm-4">20x30</div>
<div class="col-md-4">22x28</div>
</div>
</div>
<div class="col-6 col-sm-3">
<h5>Extra Large</h5>
<div class="row">
<div class="col-md-4">24x36</div>
<div class="col-md-4">27x39</div>
<div class="col-md-4">27x40</div>
</div>
</div>

Voila! We have the same result with less code, the goal we all aim to achieve.

With containers, rows, and columns, we can now think about our layout more easily. By splitting a viewport into understandable chunks and concepts, the grid system gives us a structure to apply our content.

主站蜘蛛池模板: 潜江市| 元谋县| 甘谷县| 黎川县| 武城县| 会昌县| 宜良县| 泊头市| 婺源县| 娄烦县| 阿克苏市| 玉田县| 措勤县| 仁寿县| 泰顺县| 黄山市| 繁昌县| 基隆市| 汉中市| 进贤县| 乌拉特中旗| 扎囊县| 新兴县| 永年县| 罗源县| 綦江县| 淮安市| 江川县| 达拉特旗| 尉氏县| 乃东县| 赞皇县| 额济纳旗| 阿坝县| 临泽县| 顺平县| 嘉鱼县| 苍梧县| 池州市| 苏州市| 连平县|