padding:0 auto;不能使内容居中呢?
想设置一个div居中,使用padding:0 auto;width:1000px;
为什么不能是元素居中呢?
因为使用margin:0 auto;的话,居中的两边背景色会用空白·
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
想设置一个div居中,使用padding:0 auto;width:1000px;
为什么不能是元素居中呢?
因为使用margin:0 auto;的话,居中的两边背景色会用空白·
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
具体原因不知道怎么说明,不过在w3.org上有一个说明:http://www.w3.org/TR/CSS21/visudet.html#blockwidth
然后在http://www.w3help.org/有一篇类似相关的文章,不知道是否能帮你 http://www.w3help.org/zh-cn/causes/RD8028
padding
是不可以让内容居中的;margin: 0 auto; width: 1000px;
可以让div居中,必要条件就是 必须要规定盒子的宽度;display: inline-block;
,然后在父div加上text-align: center;
也会让div居中;示例:
padding能设置为auto吗? 只有margin-left,margin-right,width能设置为auto
body 给个背景色
元素可以居中
所以LZ到底想实现什么效果