什么是做一个CSS包装的正确方法? [英] What is the correct way to do a CSS Wrapper?

查看:83
本文介绍了什么是做一个CSS包装的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是最好的方法来完成这个?什么是最佳做法?还有其他的方法吗?

最基本的例子(现场示例):



CSS:

  #wrapper {
width:500px;
margin:0 auto;

HTML:

 < body> 
< div id =wrapper>
以页面为中心的500px宽div内的一段文字
< / div>
< / body>

原理的工作原理:

创建包装并为其分配一定的宽度。然后通过使用 margin:0 auto; margin-left:auto;然后应用自动水平边距: margin-right:auto; 。自动边距确保您的元素居中。


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?

解决方案

Most basic example (live example here):

CSS:

#wrapper {
    width: 500px;
    margin: 0 auto;
}

HTML:

<body>
    <div id="wrapper">
        Piece of text inside a 500px width div centered on the page
    </div>
</body>

How the principle works:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆