Float usage in CSS

Source: Internet
Author: User

Document Flow: The browser arranges the elements in the order in which they appear in the HTML document, from left to right, from top to bottom.

The floating property is the positional property in the CSS, and is used as follows:
float: Floating direction (left, right, none);
Left is floating, right is floating, none is the default value means no float


sets the float of an element that moves away from the document stream, left or right
Until its outer margin touches the border of the parent element or the edge of another floating element
Box until

Float usage (primarily for block-level elements):

1, blocks block-level element does not specify width, the default is 100% (that will occupy a whole line).

2, blocks block-level element does not specify width but after adding float float, its width will change dynamically according to its content length, other block-level elements may be added to the left or right.

3, block-level element specifies width but after adding float float, its width does not change dynamically according to its content length (the text may overflow), other block-level elements may be added to the left or right.

4. Block-level elements added to float float away from the standard document stream, moving left or right until its margin touches the border of the parent element or the border of another floating element.

Example code:

<! DOCTYPE html>


<title>demo</title>
<style type= "Text/css" >
body{
margin:0px Auto;
padding:0px;
}

. container{
width:500px;
height:500px;
border:1px solid red;
margin:0px auto;/* Main Panel Div Center */
}

. header{
height:100px;

border:1px solid red;
Float:left; /* Add floating */
}

. main{
height:100px;
width:100px;
border:1px solid red;
Float:left; /* Add floating */
}

. footer{
height:100px;
width:100px;
border:1px solid red;
Float:right; /* Add floating */
}
</style>

<body>
<div class= "Container" >
<div class= "Header" >
Head
</div>
<div class= "Main" >
Middle
</div>
<div class= "Footer" >
Foot part
</div>
</div>
</body>

Float usage in CSS

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.