1

If I have clear:both; in the #message declaration then padding-top:30px; in the #message p declaration will be correct but if I remove the clear:both in the
#message declaration then padding-top:30px; doesn't take effect. So why do I need clear:both in the #message declaration for being able to use padding-top in the #message p declaration.

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>
nikolas
  • 8,707
  • 9
  • 50
  • 70
user2658578
  • 365
  • 2
  • 5

3 Answers3

0

Why are you floating the register element? There's no point if it has 100% width, and it causes the problem you are having. Without clearing the following element, the padding on the paragraph slides up under the floated element.

ralph.m
  • 13,468
  • 3
  • 23
  • 30
0

Because #register has float:left; it is not part of the flow. That means your #message element starts at the top of the body and only its contents gets pushed at the bottom of #register. Now the padding on top of your p has plenty room inside #message behind #register.

clear:both; forces #message to start where there is nothing on both sides of it, not even a float element, so it begins at the bottom of #register and your padding does not get behind it.

Loonie
  • 346
  • 1
  • 2
  • 8
0

Your Code: #register {float:left;}

Dont use float:left; ever, because it will affect some time in IE.. Instead you use display:inline-block or overflow:hidden. It will make your code better for all major browsers.

nikolas
  • 8,707
  • 9
  • 50
  • 70
Arun EB
  • 43
  • 1
  • 1
  • 8