首页 > 当一个dom元素被设置position: absolute后,应该出现在什么位置?

当一个dom元素被设置position: absolute后,应该出现在什么位置?

有些浏览器:如firefox(我这里是47) ie11 chrome51 仍然会在原位置,只是移出文档流不再占空间而已。
而有些浏览器:如edge chrome52 则是移动到父元素的左上角。
今天把chrome升级到52,然后自己页面整个布局都乱了,只好在外面又包裹了一层div。
为什么会这样呢?chrome51:明明是我先的
希望高人指点。

不好意思没有上代码,因为是公司项目里的。
大家都认为应该是第二种情况,但我这里可以在codepen里复现第一种情况,可以先看一下这个:http://codepen.io/almon123/pe...
把里面的test元素的position:absolute添加或删除,可以看到文字的位置是不变的,只是框内和框外的问题。
不过这个在chrome52里展现也是一样的。之后我再po上新的代码。
实际上网页基于vue开发的,也不能排除是框架的问题,前面说的有点不严谨,见笑了。


请给代码

absolute
Do not leave space for the element. Instead, position it at a specified position relative to its closest positioned ancestor if any, or otherwise relative to the initial containing block. Absolutely positioned boxes can have margins, and they do not collapse with any other margins.

绝对定位的是相对于最近的已经定位的祖先元素进行定位的,如果其所有的祖先元素都没有定位,那么就相对于初始的包含块


应该是相对于 定位的祖先元素 的left:0; top: 0; 才是合理的吧。

【热门文章】
【热门文章】