【发布时间】:2011-07-19 22:35:18
【问题描述】:
我在将边距应用于<div/> 内的子元素时遇到问题。孩子的边距会影响父母的:
<style type="text/css">
html{width:100%}
html body div{margin-left:auto;margin-right:auto;width:800px;}
div#desc{margin-top:100px;background-color:white;width:500px;font-size:24px;}
#photo{width:10px;height:10px}
</style>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div>
<div style="background-color: silver">
<div id="desc">
CSS<br/>
IS<br/>
THE<br/>
HARDEST<br/>
LANGUAGE<br/>
EVER<br/>
</div>
</div>
</div>
</body>
</html>
为什么div#desc 不将自身向下移动 100 像素,而是将整个构造移动这个值!?
【问题讨论】:
-
我可以告诉你,CSS 不会是你长久以来最难的语言。