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

Centering an element

What we really need to do is to wrap the entire content in a div tag; so let's do that. Go into the HTML file. In the line beneath the opening section tag, add <div class="wrapper"> . And right before the closing section tag, close it with </div>:

<section class="secondary-section"> 
    <div class="wrapper">
<div>...</div>
<div>...</div>
<div>...</div>
</div>
</section>

Now, switch over to the CSS file. The .wrapper tag is going to be a more reusable class. To center any element, we'll give it a margin, and we'll use the two-value syntax: top and bottom are going to be zero, and left and right are going to be auto. We also have to give it a width of 960px. Without a width, you really can't center it using this margin technique:

.wrapper { 
  margin: 0 auto; 
  width: 960px; 
} 

There, we have it; all of the content should now be centered inside this wrapper:

The wrapper class, like I said, is nice and reusable. I will use the wrapper class anywhere on the site where I want to center a collection of elements.

主站蜘蛛池模板: 南岸区| 文安县| 诸暨市| 黎川县| 庄河市| 曲靖市| 绵竹市| 上栗县| 汉沽区| 个旧市| 肇源县| 湟中县| 信阳市| 静海县| 嵊泗县| 奇台县| 阿拉善右旗| 曲松县| 桐梓县| 庄浪县| 讷河市| 新干县| 凤阳县| 镇平县| 益阳市| 潮州市| 合水县| 宁晋县| 尼勒克县| 台东县| 江城| 南通市| 五河县| 永寿县| 牟定县| 宜君县| 布拖县| 禹城市| 虎林市| 志丹县| 浙江省|