- Mastering CSS
- Rich Finelli
- 176字
- 2021-07-08 09:45:57
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.
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- 從零開始:數(shù)字圖像處理的編程基礎(chǔ)與應(yīng)用
- 新手學(xué)Visual C# 2008程序設(shè)計
- Getting Started with SQL Server 2012 Cube Development
- Hands-On Full Stack Development with Go
- Advanced Express Web Application Development
- Scala Functional Programming Patterns
- Practical Maya Programming with Python
- After Effects CC案例設(shè)計與經(jīng)典插件(視頻教學(xué)版)
- 寫給青少年的人工智能(Python版·微課視頻版)
- 金融商業(yè)數(shù)據(jù)分析:基于Python和SAS
- HTML5 WebSocket權(quán)威指南
- JavaScript全棧開發(fā)
- Python量子計算實踐:基于Qiskit和IBM Quantum Experience平臺
- VB語言程序設(shè)計教程(第2版)