Home > Web Front-end > HTML Tutorial > CSS关于div布局的小问题,请教了,谢谢_html/css_WEB-ITnose

CSS关于div布局的小问题,请教了,谢谢_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 09:09:37
Original
1082 people have browsed it

<head><style>.ABC{width:100px; height:100px; background:red; margin:auto; margin-left:20px;}</style></head><body><div class="ABC"></div></body></html>
Copy after login

为什么居中了之后不能再向左挪20px?
为什么顺序改了就提示代码错误啊?
.ABC{width:100px; height:100px; background:red; margin-left:20px; margin:auto;}
一定要使用相对定位或者绝对定位才能实现div居中后再往左或往右挪吗?


回复讨论(解决方案)

居中后,似乎不能移位

用绝对定位再margin

不会啊,我刚才用Adobe Dreamweaver 试了一下,
margin-left:20px;margin: 0px auto; //先设置左边距,然后居中,后面的居中会把左边距覆盖掉
margin: 0px auto; margin-left:20px;//先居中,然后设置左边距,后面的左边距会把居中覆盖掉
可能是里面的内容蹭的太大,可能有其他原因,,,,,,

.abc{width:100px;height:100px;background-color:#ccc;position:relative;margin-left:50%;left:-70px;}
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template