正确的方法做一个css包装 [英] Correct way to do a css wrapper
本文介绍了正确的方法做一个css包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我听说很多朋友谈论在CSS中使用封装器来定位网站的主要部分。
I have heard a lot of my friends talk about using wrappers in CSS to center the "main" part of a website.
这是最好的方法吗?什么是最佳实践?有没有其他方法?
Is this the best way to accomplish this? What is best practice? Are there other ways?
推荐答案
CSS:
#wrapper {
width: 500px;
margin: 0 auto;
}
HTML: b
<body>
<div id="wrapper">
Piece of text inside a 500px width div centered on the page
</div>
</body>
原理的工作原理:
创建包装器并为其指定一定宽度。然后使用 margin:0 auto;
或 margin-left:auto; margin-right:auto;
。自动边距确保您的元素居中。
Create your wrapper and assign it a certain width. Then apply an automatic horizontal margin to it by using margin: 0 auto;
or margin-left: auto; margin-right: auto;
. The automatic margins make sure your element is centered.
这篇关于正确的方法做一个css包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文