最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Why are elements with view-transition-name painted on top of elements with position fixed? - Stack Overflow

programmeradmin4浏览0评论

div {
  width: 50px;
  height: 50px;
  border: solid 2px black;
}

.fixed {
  position: fixed;
  top: 25px;
  left: 25px;
  background-color: red;
}

.named {
  background-color: green;
  view-transition-name: something;
}
<div class="fixed"></div>
<div class="named"></div>

div {
  width: 50px;
  height: 50px;
  border: solid 2px black;
}

.fixed {
  position: fixed;
  top: 25px;
  left: 25px;
  background-color: red;
}

.named {
  background-color: green;
  view-transition-name: something;
}
<div class="fixed"></div>
<div class="named"></div>

As far as I know, positioned elements render on top of non-positioned elements in the same stacking context.

The spec says the following:

Elements captured in a view transition during a view transition or whose view-transition-name computed value is not none (at any time):

  • Form a stacking context.
  • Are flattened in 3D transforms.
  • Form a backdrop root.

It doesn't say that elements with view-transition-name become positioned, so I don't understand why it is being rendered on top of the fixed-positioned one in the previous example.

Share Improve this question edited Feb 17 at 1:19 Adrian asked Feb 17 at 0:54 AdrianAdrian 2,0011 gold badge21 silver badges43 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

As far as I know, positioned elements render on top of non-positioned elements in the same stacking context.

That's not true, there are a lot of properties that change the painting order of elements and make them at the same level as positioned elements.

Example using opacity:

div {
  width: 50px;
  height: 50px;
  border: solid 2px black;
}

.fixed {
  position: fixed;
  top: 25px;
  left: 25px;
  background-color: red;
}

.named {
  background-color: green;
  opacity: .999;
}
<div class="fixed"></div>
<div class="named"></div>

Or clip-path

div {
  width: 50px;
  height: 50px;
  border: solid 2px black;
}

.fixed {
  position: fixed;
  top: 25px;
  left: 25px;
  background-color: red;
}

.named {
  background-color: green;
  clip-path: inset(0);
}
<div class="fixed"></div>
<div class="named"></div>

view-transition-name is one of them. It doesn't make the element positioned. It only updates its painting order to make it similar to positioned elements and since there is no z-index involved, the tree order will decide.

Related: Why does clip-path (and other properties) affect the stacking order (z-index) of elements later in DOM?

It isn't. The div you have with the class name "named" which is green and has the view-transition-name property is painted below the other div with the class name "fixed" which is red and has the position: fixed property.

发布评论

评论列表(0)

  1. 暂无评论