我不确定这是否可行,或者我是否可能需要重写很多代码,但无论如何;开始:
如果您看一下下图,我想要实现的是导航栏中的中间按钮(绿色一个)在其他 2 个菜单按钮上投下阴影,使菜单具有 3D 外观。
但是,首先我无法让盒子阴影正确落下,因为我正在使用梯形而不是盒子。此外,我不相信我具备使用 SVG 的技能。
第二个问题是,与其他 2 个按钮相比,绿色按钮的 z-index 较低,因为这就是我实现其实际形状的方式。
我的代码贴在图片下方。
HTML(其余HTML由WP动态生成,网站尚未上线。
<div class="row" id="navbar"> <!-- Navigation row -->
<div class="col-md-12">
<?php wp_nav_menu( array( 'theme_location' => 'hovedmenu' ) ); ?>
</div>
</div>
CSS:
#navbar{
z-index: 3;
position:relative;
box-shadow: 3px 3px 5px #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 a{
color:black;
}
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{
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;
}
#navbar li:nth-child(1):hover, body.home li:nth-child(1), body.home li:nth-child(1):after, 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.home #sidebar{
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){
}
#navbar li:nth-child(2):hover, body.page-id-12 .page-item-12, #navbar li:nth-child(2):hover:after, #navbar li:nth-child(2):hover:before, body.page-id-12 #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(2):before{
content: "";
position: absolute;
background: none repeat scroll 0% 0% #F00;
top: 0px;
left: 0px;
bottom: 0px;
width: 50px;
transform: skew(-40deg);
background-color: #FFF;
}
#navbar li:nth-child(2):after{
content: "";
position: absolute;
background: none repeat scroll 0% 0% #F00;
top: 0px;
right: 0px;
bottom: 0px;
width: 50px;
transform: skew(40deg);
z-index: 10;
background-color: #FFF;
}
#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:100;
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{
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;
}