[英]How can I quickly find the relatively positioned HTML parent element of an absolutely positioned child?
I am working with the following code: 我正在使用以下代码:
<div>
<div>
<div>
<div>
<div>
<div>
...
<div class="absolute">Lorem ispum</div>
...
</div>
</div>
</div>
</div>
</div>
</div>
.absolute {
position: absolute;
}
Using Chrome's DevTools, I'd like to be able to quickly find which parent <div>
element has position: relative
, so I can know which parent element is determining the origin point of my absolutely positioned element. 使用Chrome的DevTools,我希望能够快速找到哪个父<div>
元素具有position: relative
,所以我可以知道哪个父元素正在确定我绝对定位元素的原点。 I can manually inspect each of the divs to find the first parent that is set to relative
but I'm working with a deeply nested tree, so I'm wondering if there is a faster way to find the parent I'm trying to find. 我可以手动检查每个div以找到设置为relative
的第一个父级,但我正在使用深度嵌套的树,所以我想知道是否有更快的方法来查找我正在尝试查找的父级。 A Javascript snippet for the console would be an example of a suitable solution. 控制台的Javascript代码段将是合适解决方案的示例。
HTMLElement.offsetParent
is just designed to do this. HTMLElement.offsetParent
旨在实现此目的。
See this document on MDN . 请参阅MDN上的此文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.