Clear usage in Div + CSS

Source: Internet
Author: User

The clear attribute was used at the beginning, but it was used relative to float. I still don't quite understand it when I watched the video today. I checked the information and found it.

The clear attribute value has four clear: Both | left | right | none;

Purpose: The value of this attribute indicates that the edge of a floating object is not allowed.
This attribute is used to control the physical location of the float attribute in the Document Stream.

When the float attribute is set, the physical location of the object is already out of the document flow. However, most of the time we want the file flow to recognize float or float) the following elements are not affected by float. In this case, clear: Both; is required.

Clear: Left; no floating element exists on the left of the element;
Clear: Right; indicates that there is no floating element on the right of the element;

Clear: Both; indicates that no floating element exists on both sides of the element;

Clear: none indicates that floating elements are allowed on both sides.

Below is an example of applying a netizen

Clear: both;

CSS definition:
P. F1 {float: Left; width: 100px ;}
P. F2 {float: Left; width: 400px ;}

Then:
<P class = "f1"> 1st items </P>
<P class = "F2"> This is 2nd items </P>
<P> Start another row </P>

The third row above will be placed together with the first row. Why? Because when the attribute is set to float (floating), the physical location of the row is already out of the Document Stream, however, most of the time we want documents
Stream can identify float (floating), or the elements behind float (floating) will not be affected by float (floating). In this case, we need to use clear: both;
Division.

So we should change:

If you do not need to clear the float, the 3rd <p> text will be in line with the first two lines.
So we add a clear floating in the 3rd <p>.
<P class = "f1"> 1st items </P>
<P class = "F2"> This is 2nd items </P>
<P style = "clear: Both;"> Add another row </P>

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.