CSS clearing area

Source: Internet
Author: User

 
  Clear area: in Css2.1 A clearing area is introduced, when used as an element Clear The margin does not change, but the clearing area causes the element to fall under the floating element.


1 < Style Type = " Text/CSS " >
2 * {Margin: 0 ; Padding: 0 ;}
3 P {border: 1px #66cc00 solid ;}
4 IMG {
5 Width: 40px;
6 Height: 40px;
7 Float : Left;
8 Border: 1px #66cc00 solid;
9 }
10 H3 {
11 Clear: both;
12 Border: 1px #66cc00 solid;
13 }
14 Div {padding: 20px; width: 400px; Height: 400px ;}
15 < / Style>
16 < / Head>
17
18 < Body >
19 < Div >
20 < P > I am above < / P>
21 < IMG SRC = " Qq.png "   / >
22 < H3 > Below I am < / H3>
23 < / Div>

Effect:

 


H3 Settings margin-top try:

1 H3 {
2 Clear: both;
3 Border: 1px #66cc00 solid;
4 Margin-Top: 30px;
5 }

To see the effect:


unchanged, the clearing area is working. Change the following:

1 H3 {
2 clear: Both;
3 border: 1px #66cc00 solid;
4 margin - top: 60px;
5 }

Effect:

 


With16pxDistance, we can understand thisMarginCompared with the calculation of "I am on top", this clearing area is actually a bit strange. We can simply set it as follows:

1 < Style Type = " Text/CSS " >
2 * {Margin: 0 ; Padding: 0 ;}
3 P {border: 1px #66cc00 solid ;}
4 IMG {
5 Width: 40px;
6 Height: 40px;
7 Float : Left;
8 Border: 1px #66cc00 solid;
9 Margin - Bottom: 20px;
10 }
11 H3 {
12 Clear: both;
13 Border: 1px #66cc00 solid;
14 }
15 Div {padding: 20px; width: 400px; Height: 400px ;}
16 < / Style>
17 < / Head>
18
19 < Body >
20 < Div >
21 < P > I am above < / P>
22 < IMG SRC = " Qq.png "   / >
23 < H3 > Below I am < / H3>
24 < / Div>

Effect:
Ideal results!

Set the outer margin for the floating element instead of the "I am below" (clear the element). The problem is solved!


 





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.