Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 这两对标记的行为有什么不同(请参见中的)?_Html_Css_Web - Fatal编程技术网

Html 这两对标记的行为有什么不同(请参见中的)?

Html 这两对标记的行为有什么不同(请参见中的)?,html,css,web,Html,Css,Web,第一个例子 <div style="position: relative"> <div style="position: relative; top: 10px">text</div> </div> 文本 第二个例子 <div style="position: relative"> <div style="position: absolute; top: 10px">text</div> &

第一个例子

<div style="position: relative">
    <div style="position: relative; top: 10px">text</div>
</div>

文本
第二个例子

<div style="position: relative">
    <div style="position: absolute; top: 10px">text</div>
</div>

文本

完全定位的元素不会占用dom中的空间,因此外部div没有高度。这是它做的一件事。我鼓励您仔细阅读并在代码笔中进行测试,但这并不是进行此操作的地方。

第一个将在移动的元素后面留下一个“幽灵”。第二个将其从文档流中完全取出。

第一个将相对于其将要定位的位置定位内部div 10px top。
第二种方法将内部div 10px top定位到它将定位的位置,忽略外部div的填充和边框,并将其从文档流中移除。

可能重复的@ctwheels:不完全正确;问题还在于绝对定位在相对定位中的复杂性。如果是这样的话,这难道不是这个问题的重复吗?