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

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.

主站蜘蛛池模板: 临高县| 平潭县| 仙游县| 桐乡市| 县级市| 江城| 广德县| 临泉县| 胶州市| 庆云县| 平远县| 新丰县| 广元市| 水城县| 东阿县| 瑞安市| 平陆县| 融水| 礼泉县| 平武县| 华亭县| 榕江县| 衡阳县| 原平市| 临澧县| 卫辉市| 扶余县| 双江| 阳江市| 外汇| 甘洛县| 五常市| 雅安市| 许昌市| 贡觉县| 布尔津县| 杭锦旗| 色达县| 文安县| 义马市| 云龙县|