In-depth analysis of css float attributes in webpage settings

Source: Internet
Author: User
Tags html tags

Float attribute definition: In which direction the element floats


The default value is none.

Note: a floating element generates a block-level box, regardless of its own elements.


I. float syntax-TOP

Float often follows the attribute values left, right, and none.
Float: none
Float: left Float
Float: right Float to the right
Float syntax:

Float: none | left | right

Parameter value:
None: The object is not floating.
Left: The object is floating on the left.
Right: The object is floating on the right.

HTML code:

The code is as follows:

<Body>
<Div class = "main">
<Div class = "d" id = "d1"> box 1 </div>
<Div class = "d" id = "d2"> box 2 </div>
<Div class = "d" id = "d3"> Box 3 </div>
<Div class = "d" id = "d4"> Box 4 </div>
</Div>
</Body>

1. When all the sibling elements are floating elements, the height of the parent element will be zero if there is no custom width.

Css style:

The code is as follows:
. Main {
Border: 1px solid;
   }
. D {
Border: 1px solid red;
Width: 50px;
Height: 50px;
Float: left;
   }

 


2. The floating element will jump to the next row if there is not enough space in the row.

Css style:

The code is as follows:
. Main {
Border: 1px solid;
Width: 130px;
   }
. D {
Border: 1px solid red;
Width: 50px;
Height: 50px;
Float: left;
   }


3. Floating elements are separated from text streams.

Ccs style:

The code is as follows:

# D1 {
Float: left;
   }



Ss floating summary-TOP

We need to distinguish the text content from the text content to the left (text-align: left) to the right (text-align: right) style. Floating only sets the left-to-right floating style for html tags. Float floating style does not depend on the middle (floating center) style. If you need to center the label object, we will Center the text in the css layout to give you a detailed introduction (css margin ). Remember to use float: right for float to the right and float: left for float to the left.

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.