


Please give me a high score for the overflow:hidden question! _html/css_WEB-ITnose
Without over:hidden, this is the effect:
<div style="background:blue;"> <div style="width:100px; height:100px; background:red; float:left;"></div> </div>
With over:hidden, this is the effect (under IE8 and 9, the parent div still cannot be displayed) :
<div style="background:blue; overflow:hidden"> <div style="width:100px; height:100px; background:red; float:left;"></div> </div>
Plus height:1%, the parent element can be displayed in IE
<div style="background:blue; overflow:hidden height:1%"> <div style="width:100px; height:100px; background:red; float:left;"></div> </div>
Question:
1. Why after adding overflow:hidden, the DIV of the parent element can be displayed normally without being affected by the floating of the child element? What is the principle?
2. The third piece of code, height: 1%. At this time, the parent element of the parent DIV should be body, and the current body height should be 0 (because the child div is floating)? Isn't height:1% equivalent to height:0;?
Even if it is not 0, it should be a fixed value. So why can the parent div here also adapt to the height?
Please don’t reply that you should do this or that. I know other methods, but I am confused about the above two questions now.
Please read my question carefully, thank you! :)
Reply to discussion (solution)
overflow;hidden Clearing the float means that the div is removed from the state of floating in the air If the height of the parent div is not high enough, it will be affected. Try to think about it from a three-dimensional space. If you don’t understand, I wrote some in your post. . .
The following content is the answer obtained by searching online:
overflow:hidden This CSS style is commonly used by everyone, but most people’s understanding of this style is only limited to hiding overflow, and for clearing The meaning of floating is not very clear. When it comes to clearing floats, we will think of another CSS style: clear:both. I believe everyone has no problem understanding this attribute. But what does the word "floating" mean? Let’s explain it in detail below. This is a commonly used div writing method. Let’s write the style below. You can do your own experiments in DMX
#box{ width:500px; background:#000; height:500px; }
#content { float:left; width:600px; height:600px; background:red; }
Adding an overflow:hidden attribute to the box div solves this problem. We know that the overflow:hidden attribute is used to hide overflow. After adding this attribute to the box, the width and height of our content are automatically hidden. In addition, we did another experiment. After deleting the height value of the div box, we found that the height of the box was automatically stretched by the height value of the div content. Having said that, let's understand the meaning of the word "floating". Our original understanding was that it was floating on a plane, but through this experiment, we found that this was not just a floating on a plane, but a three-dimensional floating! That is to say, when the content div is added with the floating attribute, it has been separated from the box div on the side of the display. In other words, what is the width and height of the content at this time? For the box that has been separated It doesn't work. When we fully understand the meaning of the word float, we will understand the explanation of the overflow:hidden attribute and what it means to clear float. In other words, when we add the overflow:hidden attribute to the box div, the three-dimensional floating of the content and other divs with floating attributes has been cleared. This is the exact meaning of the overflow:hidden attribute to clear floats. When we do not set the height of the box div, the height of the content div will expand the box div. On the other hand, what we need to note is that when we add a height value to the box div , then no matter what the height of the div content is, the height of box is the value we set. When the height of content exceeds the height of box, the excess part will be hidden. This is what hidden overflow means!
overflow;hidden清除浮动就是指子div从飘在空中的状态落下来了,如果父div高度不够,那么就要被影响,你试着从三维的空间去想想,没看明白的话我在你的那个帖子里写了一些。。。
我看到了,但是还是没太理解~而且div默认height不是100%吧?height如果是百分比,就是只相对于父元素的,div里如果没内容那height就应该是0~
没加over:hidden是这样的效果:
HTML code
加了over:hidden是这样的效果(在IE8、9下,仍然无法显示父div):……
http://www.chinaz.com/design/2008/0818/35473.shtml参考这个
引用楼主 wsy87217 的回复:
没加over:hidden是这样的效果:
HTML code
加了over:hidden是这样的效果(……
嗯我好像明白了!
第2个问题能帮我看下吗?
1,overflow:hidden;是让子元素不溢出,而本身的div没有设置height属性,这样一来标准浏览器就去检测子元素的高。
2,height:1%是用来触发元素hasLayout,类似的可以用zoom:1替代;
引用 4 楼 wangyao1135 的回复:
引用楼主 wsy87217 的回复:
没加over:hidden是这样的效果:
HTML code
……
我没有设置body的高度,你看看效果。body的高度是0吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">body{ background:#FF0000;}</style></head><body></body></html>
1,overflow:hidden;是让子元素不溢出,而本身的div没有设置height属性,这样一来标准浏览器就去检测子元素的高。
2,height:1%是用来触发元素hasLayout,类似的可以用zoom:1替代;
额。。。没太看明白~
引用 5 楼 wsy87217 的回复:
引用 4 楼 wangyao1135 的回复:
引用楼主 wsy87217 的回复:
没加over:hidden是这样的效果:
HTML code
那浏览器显示的效果,说明了什么问题呢。。。。
浏览器的显示效果应该能说明body不是没有高度的吧。默认的应该是和浏览器打开的一样大的。应该是宽是100%高度也是
1,浮动float 是指示一个元素忽略自己和同级的块(block)属性,尽可能紧凑地利用空间;
overflow是指示一个元素,如何占有自己的block空间;
如果父元素没有定义overflow,游览器会只有一次布局呈现,把子元素显示完了就完了。如果父元素有overflow,游览器在把子元素呈现完后会再回溯一次,重新计算空间,计算并调整父元素的显示范围。然后才继续下面的元素布局。
2,流式布局的内的元素高度百分比是无效的,百分比只有在明确指定了高度的盒式模型内才有效。在流式布局内,高度百分比会直接被忽略。
3,以上其实为本人猜测,没有深入浏览器内部,也没有见到正式的官方解释。
谢谢大家!
稍微明白点了!:)

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

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

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.
