


According to CSS specifications, floating elements (float) will be moved out of the document flow and will not affect the layout of block boxes but only the arrangement of inline boxes (usually text). Therefore, when its height exceeds the containing container, the general parent container will not automatically stretch to close the floating element. But sometimes we need this automatic closing behavior. How to deal with it?
One way is to insert an additional tag into the parent container and make it clear to expand the parent container. This method has good browser compatibility and no problems. The disadvantage is that it requires additional (and usually semantically unsemantic) tags, so I personally don't like it.
Later there was a new way, using the :after pseudo-class to dynamically embed an element for clearing floats. This method has the same principle as the previous one, the only difference is that this additional content Generated with CSS, but considering that IE does not support :after, I had to do a lot of hacks. This method has general compatibility, but after various hacks, it can cope with different browsers. At the same time, it can ensure that the html is relatively clean, so it is still used more often.
Later, someone discovered that setting the overflow of the parent container to a value other than visible can close the floating element in a standard-compliant browser. IE naturally does not support it, so this method is the same as the above method. Both methods handle IE differently (specifically triggering layout). The difference is that overflow is not as troublesome as the :after pseudo-class. It also has shortcomings. Overflow may cause some minor conflicts.
Before using overflow, there was another way to use float, which is to make the parent container float. This takes advantage of a characteristic of floating elements? Floating elements will close floating elements. This method has good results in IE/Win and standard-compatible browsers, but the shortcomings are also obvious. The parent container may not float just because it wants to float. After all, floating is a special behavior, and sometimes the layout is not correct. Allowing it to float is also normal. Although float elements can be closed in IE and standard-compliant browsers, the principle is different. In IE/Win, float triggers layout and therefore closes the float. In standard-compliant browsers, float is actually the same as the previous one. The principle of overflow in this method is the same, resulting in a "block-level formatting range"?? This is a phenomenon mentioned in the CSS specification. It often has some independence. One of its characteristics is that it will automatically close the internal float. element.
According to the specification, the following types of elements will generate a block-level formatting range:
● Floating elements, either left or right.
● Absolutely positioned elements.
● Inline-block element, but this gecko does not currently support it.
● table-cell type elements, in fact, table, table-head-group, table-row, etc. are also acceptable, as well as inline-table (not supported by gecko), because they all indirectly generate an anonymous table -cell.
● Overflow is an element whose value is not visible.
So, it turns out that we can also have so many methods to close a floating element in standard-compliant browsers, and only CSS is needed, nothing else is needed. By the way, in addition to overflow, the above has an additional effect of automatically shrinking the width of the parent container.
For IE/Win, it has its own system, which is layout. Elements with layout will automatically close floating elements. Let’s take a look at the CSS properties that trigger layout. You will find that it is similar to the block-level formatting above. Ranges have many similarities:
● Floated element
● Absolutely positioned element
● display:inline-block
● zoom
● width/height
● overflow/ overflow-x/overflow-y [IE7 new]
● max/min-width/height [IE7 new]
From the above, there are many ways to close floating elements in IE, and naturally they all have their own Limitations, either having side effects or using non-standard properties (cannot pass validation).
Another thing to mention is display:inline-block. This attribute is of little use to IE. The actual effect is just to secretly add layout to an element, but standards-compliant browsers recognize this attribute. , so in order not to affect these browsers, you need to set the display back to the default. There is a bug in IE here. If you define display:inline-block first, and then set the display back to block (these two displays must be placed in two CSS statements one after another to be effective), then the layout will not disappear, and at the same time, the layout will not disappear. It will not affect other browsers, so for now, this is also a good way to trigger layout:
.gainlayout{display:inline-block;}
.gainlayout{display:block;}
So there are many ways to close floating elements across browsers. How to use these CSS properties together requires a detailed analysis of the specific situation. It is also necessary to flexibly apply conditional comments. If it doesn’t work, we will come back. There is also clear that can be used.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools