<div style="background:blue; overflow:hidden;"> <div style="width:100px; height:100px; background:red; float:left;"></div></div>
一直没想明白为什么使用overflow:hidden可以清除浮动呢?这是什么原理啊?
另外这种方法是不是在IE9里不行了?我刚才试了下,不行。但在火狐里还可以。
回复讨论(解决方案)
没发觉能清除
没发觉能清除
可是我从网上看的教学视频,他里面讲的清除float有两种办法:1、clear 2、overflow:hidden;
而且在他那确实清除成功了,但在我这(IE9)不行。
为什么必须得给父DIV赋高呢?
另外用over:hidden消除浮动是什么原理啊?
<div style="background:#06F; overflow:hidden;"> <div style="height:50px; width:100px; float:left; background:#F00;"></div> <div style="height:100px; width:100px; background:#F0F;"></div> </div>
你这样写的时候你测试一下,并没有清除浮动啊?
HTML code
没加over:hidden是这样的效果:
<div style="background:blue;"> <div style="width:100px; height:100px; background:red; float:left;"></div></div>
加了over:hidden是这样的效果:
<div style="background:blue; overflow:hidden;"> <div style="width:100px; height:100px; background:red; float:left;"></div></div>
我所说的清除浮动,不是对后面元素的影响,是消除了对父元素的影响。
我的问题是,为什么over:hidden会实现这样的效果?
谢谢!
只知道对该div有溢出隐藏功能 至于浮动清除浮动 没发觉
算了我再开个帖子吧
说一下个人理解:
div不指定width和height时,默认width为0,height为100%;
不加overflow:hidden时,子div受float影响脱离父div的束缚,父div默认没有高度,自然就是第一个图的效果;
加上overflow:hidden时,所谓消除了浮动,那么子div自然就要使父div的高度为100px、宽度默认100%
实际上,overflow:hidden影响的只是垂直空间上的浮动,并不影响水平面上的浮动,将float设置为right可以看得更加明白。(仅仅是个人理解,不知道正确不。。。。。。)

Self-closingtagsinHTMLandXMLaretagsthatclosethemselveswithoutneedingaseparateclosingtag,simplifyingmarkupstructureandenhancingcodingefficiency.1)TheyareessentialinXMLforelementswithoutcontent,ensuringwell-formeddocuments.2)InHTML5,usageisflexiblebutr

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

Boolean attributes are special attributes in HTML that are activated without a value. 1. The Boolean attribute controls the behavior of the element by whether it exists or not, such as disabled disable the input box. 2.Their working principle is to change element behavior according to the existence of attributes when the browser parses. 3. The basic usage is to directly add attributes, and the advanced usage can be dynamically controlled through JavaScript. 4. Common mistakes are mistakenly thinking that values need to be set, and the correct writing method should be concise. 5. The best practice is to keep the code concise and use Boolean properties reasonably to optimize web page performance and user experience.

HTML code can be cleaner with online validators, integrated tools and automated processes. 1) Use W3CMarkupValidationService to verify HTML code online. 2) Install and configure HTMLHint extension in VisualStudioCode for real-time verification. 3) Use HTMLTidy to automatically verify and clean HTML files in the construction process.

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

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.


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

Atom editor mac version download
The most popular open source editor

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!
