Understanding of float attributes in CSS

Source: Internet
Author: User

First, you must know two things:

1. the browser displays the object in the stream layout according to the object declaration sequence in the HTML code.

2. almost all objects in HTML are divided into two types by default: block objects and in-line objects. the default display status of a block occupies the entire row. The in-line object is the opposite, allowing other objects to be displayed in one row.

 

Now let's look at the float attribute. Its function is to change the default display mode of the block object. After the block object is set with the float attribute, it will no longer occupy one row.

 

You can see the following example:

 

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">

<HTML>

<HEAD>

<Style>

. Left

{

Background-color: # cccccc;

Border: 2px solid #333333;

Width: 200px;

Height: 100px;

}

. Leftfloat

{

Background-color: # cccccc;

Border: 2px solid #333333;

Width: 200px;

Height: 100px;

Float: left;

}

. Right

{

Background-color: # cccccc;

Border: 2px solid #333333;

Height: 100px;

}

</Style>

</HEAD>

 

<BODY>

<Div class = "left"> div left float: none </div>

<Div class = "right"> div right </div>

 

<Div class = "leftfloat"> div left float: left </div>

<Div class = "right"> div right </div>

 

<Span class = "left"> span left float: none </span>

<Span class = "right"> span right </span>

</BODY>

</HTML>

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.