如何在父母的子女之上定位父母的子女?

编程入门 行业动态 更新时间:2024-10-15 16:19:09
本文介绍了如何在父母的子女之上定位父母的子女?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个容器div,它有 background-color:red; 。这个容器大约有12个孩子,而最后一个孩子有 background-color:blue; 。我试图用 background-color:blue 将容器移动到孩子的顶部。我为容器使用了更高的Z-index,但它仍然落后于孩子。

.no1 {width:800px; height:300px;背景颜色:红色;位置:相对; z-index:999;}。no2 {position:relative;宽度:500px; height:200px;背景颜色:蓝色; z-index:1;}。no3 {position:relative;}。no4 {position:relative;}。no5 {position:relative;}

< div class =no1> < DIV> < DIV> < div class =no3> < DIV> < div class =no4> < DIV> < DIV> < DIV> < div class =no5> < div class =no2> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / div>< / div>

这是JSFiddle

解决方案

div>

你可以从父母中删除z-index,并给孩子一个负z-index

.no1 {width:800px;高度:300像素;背景色:红色; position:relative;}。no2 {position:relative;宽度:500像素;高度:200像素;背景色:蓝色; z-index:-1} .no3 {position:relative; } .no4 {position:relative; } .no5 {position:relative; }

< div class =no1> < DIV> < DIV> < div class =no3> < DIV> < div class =no4> < DIV> < DIV> < DIV> < div class =no5> < div class =no2> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / DIV> < / div>< / div>

I have a container div and it has background-color: red;. There are about 12 children to this container, and the last child has background-color: blue;. I tried to move the container to top of the child with background-color: blue. I used a higher z-index for the container but it is still behind the child.

.no1 { width: 800px; height: 300px; background-color: red; position: relative; z-index: 999; } .no2 { position: relative; width: 500px; height: 200px; background-color: blue; z-index: 1; } .no3 { position: relative; } .no4 { position: relative; } .no5 { position: relative; }

<div class="no1"> <div> <div> <div class="no3"> <div> <div class="no4"> <div> <div> <div> <div class="no5"> <div class="no2"> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>

Here is the JSFiddle

解决方案

You could remove the z-index from the parent and give the child a negative z-index

.no1 { width:800px; height:300px; background-color:red; position:relative; } .no2 { position:relative; width:500px; height:200px; background-color:blue; z-index: -1 } .no3 { position:relative; } .no4 { position:relative; } .no5 { position:relative; }

<div class="no1"> <div> <div> <div class="no3"> <div> <div class="no4"> <div> <div> <div> <div class="no5"> <div class="no2"> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div> </div>

更多推荐

如何在父母的子女之上定位父母的子女?

本文发布于:2023-10-28 03:56:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535442.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子女   父母   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!