DIV+CSS Block Box Floating design

Source: Internet
Author: User

In the layout of the page, you can use absolute positioning, but because the location of the other blocks when adjusting a block box does not change accordingly, so this is not the preferred way of layout. However, use the floating block box to move left or right until its outer edge touches the border containing its chunk or another floating-mad border. And because the float box is not in the normal flow of the document, the Block box in the normal flow of the document behaves as if the float box does not exist.

This article summarizes several examples of simple block box floats:

1. Do not float block box sorting


2. Float the first block box to the right

To redefine the #one selector, you only need to add one line of code:

#one {float:right;background:red;}

The results of the operation are as follows:



3. Set the first left float

In order to let you see the effect, you have to adjust the size of three blocks, so directly re-write the code.


Operation Result:

It is not difficult to see that the box (2) is covered by the box (1). Only the width of the extra 40px can be seen. Since the box (1) floats, it is not part of the document flow range, the equivalent of its original position is empty, so the box (2) naturally fill up.

4. Set three boxes all floating to the left

This only needs to add a line of code in the div{} in Example 1:

Float:left;
Operating effect:


5. Set three boxes to the left (out of space)

You only need to modify the size of the three blocks to

Operation Result:

If there is not enough space, the block will automatically move down.

6. The third block was first "stuck"

Block 3 does not have enough space on the top, when the move down, the block of more than 1 blocks will automatically block the movement of Block 3.

Finally, we introduce a property: Clear (Clears the property, specifies whether an element allows an element to float next to it)

Clear:none;clear:left;clear:right;clear:both;
There are a total of such values, respectively, corresponding to different removal effects. Flexible use of this property, a lot of problems can be easily solved.



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.