First way:
Because the floating box is not in the normal document flow, it does not occupy space. Such as the following code:
.news {
background-color: gray;
border: 1px solid black;
}
.news img {
float:left;
}
.news p {
float:right;
}
Some text
But because the floating element is out of the document flow, the div surrounding the image and text does not occupy space. How to make the surrounding element visually surround the floating element? Clear needs to be applied somewhere on this element. Unfortunately there is no element to clean in this case, so add an empty element below the last paragraph and clean it.
Add:
.clear {clear:both}
...
This is the first way to clean up floats, but this method adds meaningless tags.
The second wayis not to clean up the floating text and images, but to select the floating container div:
.news {
background- color:gray;
border:solid 1px black;
float:left; }
...
But with Elements at the same level as the div will be affected.
The third wayis to use the overflow attribute. Applying the overflow attribute with a value of hidden or auto has a useful side effect, which automatically cleans any contained floating elements:
.news {
background-color:gray;
Border:solid 1px black; , use the :after pseudo-class and content declaration to add new content at the end of the specified existing content:
.clear:after { content: ".";
height:0;
visibility: hidden;
display: block;
clear: both; ;div class="news clear">
...
This method works in most modern browsers, Taobao homepage also uses this method to clear floats, but it does not work in IE6 and lower versions. The following hack is required under IE6:
.clear {
display:inline-block;
}
* html .clear {height:1%;}
.clear {display:block;}
Others: http://my.oschina.net/leipeng/blog/221125
The article is excerpted from: The Road to the Front End

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
