Home  >  Article  >  Web Front-end  >  Several methods for clearing floats in HTML

Several methods for clearing floats in HTML

不言
不言Original
2018-06-25 09:30:221999browse

This article talks about 6 ways to clear the floating HTML elements for your reference. Please see below for details

What will happen when using display: inline-block:

1. Make block elements display in one line

2. Make inline support width and height

3. Line breaks are parsed

4. When not set, the width is Content expansion

5. Support block tags in IE6 and 7

Because the inline-block attribute is parsed when wrapping (there is a gap), the solution is to use float:left/right

Situations that occur when using float:

1. Make the block element display in one line
2. Make the inline element support width and height
3. Do not set the width and height When the width is stretched by the content
4. Line breaks are not parsed (so when using inline elements, you can use floats to clear gaps)
5. Adding floats to elements will break away from the document flow and move in a specified direction. , until it hits the boundary of the parent or another floating element stops (the document flow is the position occupied by the displayable objects in the document when arranged)





无标题文档


p1

p2

span1 span2

The following code only floats box1, then box1 and box2 overlap Together. If both are floating, there will be no overlap.





无标题文档


Methods to clear floating:
1. Add floats to the parent as well
(In this case, when the parent margin: 0 auto; Not centered)





无标题文档


2. Add display:inline-block; to the parent (same as method 1, not centered. Only IE6 and 7 are centered)





无标题文档


3. Add5394d62b37c0d1016baca90bf99fbfbf94b3e26ee717c64999d7867364b1b4a3

under the floating element .clear{ height:0px;font-size:0;clear:both; }But under IE6, the block element has a minimum height, that is, when height





无标题文档


4. Add 079d205125cc08b5a6372726f48e58b9





无标题文档



under the floating element. 5. Add {zoom:1;}

to the parent of the floating element.
:after{content:""; display:block;clear:both;}




无标题文档


6. Add overflow:auto;





无标题文档


to the parent of the floating element. The above is the entire content of this article. I hope it will be helpful to everyone’s learning. For more related content, please Follow PHP Chinese website!

Related recommendations:

How to use Html to block the right-click menu and left-click swipe function

##About HTML Text formatting code

#

The above is the detailed content of Several methods for clearing floats in HTML. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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