什么是定位祖先? [英] What is a positioned ancestor?

查看:73
本文介绍了什么是定位祖先?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读文章在MDN上.它谈到可以将绝对定位元素固定到相对于其最近定位的祖先元素的位置".

I am reading the "Positioning Techniques" of this article on MDN. It talks about "Absolute positioning elements can be fixed to a position relative to its nearest positioned ancestor element".

我对定位祖先"的理解是具有除静态以外的任何位置属性的祖先.但是我需要专家的意见来验证我的想法.

My understanding of "positioned ancestor" is an ancestor with any position property other than static. But I need expert opinions to verify my thought.

推荐答案

在指代 positioned祖先时,我们指的是最接近祖先的元素,该元素具有设置的 position 值,不是 static (默认).

When referring to positioned ancestor we mean the closest ancestor to the element with a set position value, other than static (which is default).

所以这里有两个假设:

  1. 如果有多个已定位祖先,则表示最接近的.
  2. 如果某个祖先的集合设置了 position:static (大概是由JavaScript设置的,以便更改定位的祖先"),我们并不是说祖先.
  1. In case there are more than one positioned ancestors we mean the closest.
  2. In case there is an ancestor with a set position:static (presumably set by JavaScript, in order to change the "positioned ancestor") we don't mean that ancestor.

为什么这很重要?因为定位祖先" 是参考,当给后代指定 position时,将根据该参考计算诸如 left top 之类的属性:绝对.也称为后代的参考元素/父对象".
另外,如果最接近的祖先具有一组 z-index (而不是 auto ),则会为其后代创建一个堆叠上下文.

Why is this important? Because the "positioned ancestor" is the reference from which properties like left and top are calculated, when the descendant is given position:absolute. It's also called "the reference element/parent" of the descendant.
Also, if this closest ancestor has a set z-index (other than auto), it creates a stacking context for its descendants.

这篇关于什么是定位祖先?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆