Home >Web Front-end >HTML Tutorial >CSS floating related solutions_html/css_WEB-ITnose

CSS floating related solutions_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:38:57883browse

Problems caused by floating elements:

1. When the first-level child elements of the parent element are all floating elements, the height of the parent element cannot be expanded, affecting the height of the parent element. Elements at the same level of the element

2. Non-floating elements (content) at the same level as the floating element will follow

3. If the first element is not floated, the elements before it will It also needs to be floated, otherwise it will affect the structure of the page display

Solution:

Use the clear:both; attribute in CSS to clear the float of the element. 2. Question 3. For question 1, add the following styles and add clearfix style to the parent element:

.clearfix:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;}.clearfix{display: inline-block;} /* for IE/Mac */

Several ways to clear floats:

1. Additional tags Method, 56c5d33419803948326578624852419716b28748ea4df4d9c2150843fecfba68 (Disadvantage: However, this method will add additional tags and make the HTML structure look less concise.)

2. Use after Pseudo class (only applicable to non-IE browsers)

#parent:after{    content:".";    height:0;    visibility:hidden;    display:block;    clear:both;}

3. Floating external elements

4. Set overflow to hidden or auto zoom:1 (for compatibility with IE6)

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