如果我clear:both;
在#message
声明中有,那么padding-top:30px;
在
#message p
声明中将是正确的,但如果我clear:both
在
#message
声明中删除,则padding-top:30px;
不会生效。那么为什么我需要clear:both
在#message
声明中才能
padding-top
在#message p
声明中使用。
CSS
body {
margin: 5px;
padding: 0;
font-family: Arial, sans-serif;
font-size: small;
text-align: center;
width: 768px;
}
#register {
float: left;
width: 100%;
margin: 0;
padding: 0;
list-style: none;
color: #690;
background: #BDDB62;
}
#register a {
text-decoration: none;
color: #360;
}
#reg {
float: left;
margin: 0;
padding: 8px 14px;
}
#find {
float: right;
margin: 0;
padding: 8px 14px;
}
#message {
clear: both;
font-weight: bold;
font-size: 110%;
color: #fff;
text-align: center;
background: #92B91C;
}
#message p {
margin: 0;
padding-top: 30px;
}
#message strong { text-transform: uppercase }
#message a {
margin: 0 0 0 6px;
padding: 2px 15px;
text-decoration: none;
font-weight: normal;
color: #fff;
}
HTML
<ul id="register">
<li id="reg">Not registered? <a href="#">Register</a> now!</li>
<li id="find"><a href="#">Find a store</a></li>
</ul>
<div id="message">
<p>
<strong>Special this week:</strong> $2 shipping on all orders!
<a href="#">LEARN MORE</a>
</p>
</div>