简体   繁体   English

为什么相对工作内部没有绝对定位?

[英]Why doesn't absolute positioning inside relative work?

I'm a complete beginner at webprogramming so here's my problem: 我是Web编程的完整入门者,所以这是我的问题:

This what I have right now. 就是我现在所拥有的。 However, as soon as I add position: absolute to the two listings the height of the div-element decreases to 1px which is what I do not want. 但是,一旦我在两个清单中添加position: absolute ,div元素的高度就会降低到1px,这是我不想要的。 http://jsfiddle.net/H2V7W/6/ http://jsfiddle.net/H2V7W/6/

 div { position: relative; border: 1px blue solid; } ul, ol { border: 1px red solid; } div { position: relative; border: 1px blue solid; } ul, ol { border: 1px red solid; position: absolute; } 
 <div> <ul> <li>1</li> </ul> <ol> <li>a</li> </ol> </div> 

Why is this happening that the two listings seem to have jumped out completely of div? 为什么这两个列表似乎完全跳出了div?

I thought that I would have "full control" once I do absolute positioning inside relative? 我以为一旦在亲戚中进行绝对定位,我将拥有“完全控制权”?

According to the spec , 根据规范

absolute 绝对
The box's position (and possibly size) is specified with the 'top', 'right', 'bottom', and 'left' properties. 框的位置(可能还有尺寸)由“顶部”,“右侧”,“底部”和“左侧”属性指定。 These properties specify offsets with respect to the box's containing block. 这些属性指定相对于框的包含块的偏移量。 Absolutely positioned boxes are taken out of the normal flow. 绝对定位的盒子将从正常流程中取出。 This means they have no impact on the layout of later siblings. 这意味着它们对以后的兄弟姐妹的布局没有影响。 Also, though absolutely positioned boxes have margins, they do not collapse with any other margins. 同样,尽管绝对定位的框具有边距,但它们不会与其他任何边距一起折叠。

Also see this MDN article . 另请参阅此MDN文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM