Z 索引绝对定位元素低于父级,具有 z 索引解决方法
Z-index absolute positioned element below parent with z-index workaround?
我正在尝试使用 CSS 伪元素在导航栏中的按钮后面创建阴影。我想将伪元素放在中间按钮后面,但在导航栏中其他两个按钮的前面。
我尝试过用z-index
这样做,但我意识到你不能使用 z-index
将伪元素放在其父元素后面,因此我正在寻找解决方法。
这就是我所指的网站。
这是导航栏的 CSS
#navbar{
z-index: 3;
position:relative;
box-shadow: 0px 4px 10px #000;
}
#navbar li{
display:inline-block;
height:100px;
line-height:100px;
width:33.333333333333333%;
color:black;
text-align:center;
font-size:22px;
font-weight:bold;
background-color:white;
padding:0;
}
#navbar li:nth-child(2):after{
position:absolute;
top:-42;
left:78;
z-index:1;
content:"";
height:150px;
width:170px;
-webkit-transform: perspective(200px) rotateX(57.5deg) scale(1.1,1.1);
box-shadow: 0 0 30px rgba(0,0,0,0.3);
}
#navbar li:nth-child(2) a{
position:relative;
z-index:100;
}
#navbar li a{
color:black;
display:inline-block;
}
body.page-id-14 #sidebar, body.page-id-14 #content{
box-shadow: none;
height:770px;
overflow:hidden;
}
#menu-hovedmenu{
margin:0;
}
body.page-id-10 #navbar li:nth-child(1) > a, body.page-id-12 #navbar li:nth-child(2) > a, body.page-id-14 #navbar li:nth-child(3) > a, body.single-malerservice #navbar li:nth-child(1) a, body.single-industrilakering #navbar li:nth-child(2) a, body.single-gulvservice #navbar li:nth-child(3) a{
color:white;
}
#navbar li:hover{
color:white;
}
#navbar li:nth-child(1), #navbar li:nth-child(2), #navbar li:nth-child(3){
float:left;
position:relative;
cursor:pointer;
text-align: center;
border-top-left-radius: 5px;
}
#navbar li:nth-child(3){
border-top-right-radius: 5px;
}
#navbar li:nth-child(1):hover, body.page-id-10 #navbar li:nth-child(1):after, body.page-id-10 .page-item-10, #navbar li:nth-child(1):hover:after, body.page-id-10 #sidebar, body.single-malerservice #sidebar, body.single-malerservice #navbar li:nth-child(1), body.single-malerservice #navbar li:nth-child(1):after{
color: white;
background-color: #234e7b;
background-image: -webkit-linear-gradient(top, #234e7b, #0d2951);
background-image: -moz-linear-gradient(top, #234e7b, #0d2951);
background-image: -ms-linear-gradient(top, #234e7b, #0d2951);
background-image: -o-linear-gradient(top, #234e7b, #0d2951);
background-image: linear-gradient(top, #234e7b, #0d2951);
}
#navbar li:nth-child(1):after{
content: "";
position: absolute;
background: none repeat scroll 0% 0% #00F;
top: 0px;
right: -51px;
bottom: 0px;
width: 100px;
transform: skew(-40deg);
z-index: 1;
background-color: #FFF;
}
#navbar li:nth-child(2):hover, body.page-id-12 .page-item-12, #navbar li:nth-child(2):hover:after, body.page-id-12 #sidebar, body.single-industrilakering #navbar li:nth-child(2), body.single-industrilakering #sidebar{
color:white;
background-color: #12910f;
background-image: -webkit-linear-gradient(top, #12910f, #0b4b0e);
background-image: -moz-linear-gradient(top, #12910f, #0b4b0e);
background-image: -ms-linear-gradient(top, #12910f, #0b4b0e);
background-image: -o-linear-gradient(top, #12910f, #0b4b0e);
background-image: linear-gradient(top, #12910f, #0b4b0e);
}
#navbar li:nth-child(3):before{
content: "";
position: absolute;
background: none repeat scroll 0% 0% #F00;
top: 0px;
left: -51px;
bottom: 0px;
width: 100px;
transform: skew(40deg);
z-index:10;
background-color: #FFF;
}
body.page-id-14 #navbar .page-item-14, body.page-id-14 #navbar li:nth-child(3):before, #navbar li:nth-child(3):hover, #navbar li:nth-child(3):hover:before, body.single-gulvservice #navbar li:nth-child(3), body.single-gulvservice #navbar li:nth-child(3):before{
background-image: -webkit-linear-gradient(top, #f83838, #c00000);
background-image: -moz-linear-gradient(top, #f83838, #c00000);
background-image: -ms-linear-gradient(top, #f83838, #c00000);
background-image: -o-linear-gradient(top, #f83838, #c00000);
background-image: linear-gradient(top, #f83838, #c00000);
}
#navbar li:hover > a{
color:white;
text-decoration: none;
}
尝试使用 box-shadow
、 border
和 outline
片段
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>shadow</title>
<style>
.box {
-webkit-box-shadow: -1px 2px 8px 8px rgba(0, 0, 0, 0.75);
-moz-box-shadow: -1px 2px 8px 8px rgba(0, 0, 0, 0.75);
box-shadow: -1px 2px 8px 8px rgba(0, 0, 0, 0.75);
border: 1px outset #888;
outline: 3px inset #aaa;
width: 300px;
height: 300px;
margin: 20px auto;
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
相关文章:
- 如何通过Jquery从具有相同名称但不同索引的输入中获取所有值
- 将一个元素放在具有相同z索引的其他元素前面
- 触发具有较低Z索引值的DOM元素的事件
- 如何在 ng-repeat 中使用 anchorScroll() 以在索引 x 处具有开始视图
- 猫头鹰旋转木马2从具有特定内容的元素接收项目索引
- 如何查找具有行和列索引的特定单元格的内容
- Catch mouseover和onclick查找具有不同z索引的元素
- Hogan.js-引用具有特定索引的项
- 获取具有值的序列中最后一个输入字段的索引
- 用于查找在 jQuery 元素集中具有特定类的元素的索引的单行代码
- Jquery 复制了具有特定索引的 html 类,无法识别点击事件
- Z 索引绝对定位元素低于父级,具有 z 索引解决方法
- 如何有效地搜索具有介于 jquery 之间的索引的 name 属性的输入
- 以 $_POST 为单位的未定义索引,具有多项选择
- 检测数组中接近且具有相同索引值的数字
- 在 Firefox 中,当选择具有位置和 z 索引时,为什么更改事件不会在选项卡上触发
- JavaScript - 检查一个数组是否与另一个数组具有相同的索引
- 从具有更改索引的对象中删除元素
- 如何使用 jQuery 获取具有相同 z 索引的元素
- 获取在列表视图中具有特定首字母的索引元素