Web page layout method: clear floating

php中世界最好的语言
Release: 2018-03-13 11:00:30
Original
1685 people have browsed it

This time I will bring you the layout method of the web pageClear floating, what are theprecautionsfor clearing floating, the following is a practical case, let's take a look.

The height problem of the box

1. The height of the box in the standard flow can be supported by the content height;
2. The floating content in the floating flow cannot support the height of the box;

Why do we need to be clear about floating?

Between adjacent boxes, if the front box has no height, then the floating element in the back box will look for the floating element in the front box. This will It leads to confusion in the interface, so it is necessary to clear the float;

Clear the float method one:

Solution:

Set the height of the previous parent element

Notes :

In enterprise development, we can write height without writing height, so this method is rarely used;

CSS:

Copy after login

body:

我是文字1

我是文字1

我是文字1

我是文字2

我是文字2

我是文字2

Copy after login

Clear floating method two:

Solution:

Add the clear:both; attribute to the back box

clear attribute value:

none: Default value, sort according to the sorting rules of floating elements (left floating elements look for left floating elements, right floating elements look for right floating elements)
left: Do not look for the previous left floating element (that is: do not compare it with the previous left floating element) Floating elements are displayed in one line)
right: Do not look for the previous right floating element
both: Do not look for the previous left floating element and right floating element

Note:

When After we add the clear attribute to an element, the margin attribute of this attribute will become invalid; so it is not recommended to use

CSS:

Copy after login

Clear floating method three:

Solution:

Exterior wall method: add an additional block-level element between two boxes with floating child elements; and set the clear: both; attribute;

Notes:

Exterior wall method allows the second box to use the margin-top attribute,
Exterior wall method does not allow the first box to use themargin-bottomattribute,
However The margin effect can be achieved by setting the height of additional tags;
This technique is widely used in Sohu, but due to the need to add a large number of meaningless tags, it is not recommended;

CSS:

 

我是文字1

我是文字1

我是文字1

//外墙法:在两个有浮动子元素的盒子之间添加一个额外的块级元素;

我是文字2

我是文字2

我是文字2

Copy after login

Clear floating method four:

Solution:

Inner wall method:
1Add an additional block-level element at the end of all child elements in the first box,
2Set the clear: both; attribute to this additional block-level element

Note:

The inner wall method allows the second box to use the margin-top attribute
The inner wall method allows the first box to use the margin-bottom attribute

The difference between the exterior wall method and the interior wall method?

The exterior wall method cannot support the height of the first box. The inner wall method can support the height of the first box

In enterprise developmentThe partition methodis not commonly used to clear floating (partition wall method: external wall method and internal wall method) Wall method)

CSS:


我是文字1

我是文字1

我是文字1

//设置内墙

我是文字2

我是文字2

我是文字2

Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

CSS background and sprite

How to use CSS display mode

The above is the detailed content of Web page layout method: clear floating. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!