我有一个特殊的on-hover属性,它基本上强调了我以漂亮的方式悬停的东西。
现在下划线的颜色设置为白色,我想知道是否有办法改变不同物品的颜色?
我不知道该怎么做,我已经尝试过内联更改,但由于它是:
.navbar li:before {
content: "";
position: absolute;
z-index: -1;
left: 50%;
right: 50%;
bottom: 0;
background: white;
height: 4px;
-webkit-transition-property: left, right;
transition-property: left, right;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
由于这个
,我不确定它是否会内联工作编辑---
我应该提到,如果你点击“合同”标签,会出现一个新列表,并且我试图以某种方式改变每个下划线的颜色,傻傻的我!
答案 0 :(得分:5)
使用nth-child(n)选择器,如下所示:
{{1}}
答案 1 :(得分:2)
试试这个:nth-child()选择器将解决你的问题
bazel build --genrule_strategy=standalone --spawn_strategy=standalone //path/to/your:target

$('.navbar ul li:nth-child(2) a').click(function() {
$(".additional").slideToggle()
});

body {
background-color: #fff;
margin: 0;
font-family: Arial;
color: #333;
}
header {
background-color: #333;
position: fixed;
top: 0;
width: 100%;
}
.navbar {
display: block;
text-align: center;
}
.navbar ul {
list-style-type: none;
padding: 0;
margin: 0;
}
.navbar li {
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
position: relative;
}
.navbar li:before {
content: "";
position: absolute;
z-index: -1;
left: 50%;
right: 50%;
bottom: 0;
background: white;
height: 4px;
-webkit-transition-property: left, right;
transition-property: left, right;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.navbar li:hover:before, navbar li:focus:before, .navbar li:active:before {
left: 0;
right: 0;
}
.navbar li a {
padding: 25px;
display: block;
height: 100%;
color: white;
text-decoration: none;
}
.title {
height: 80px;
padding: 2px;
background-color: #fff;
}
.container {
margin-top: 150px;
padding-top: 50px;
}
.home {
margin-top: 10px;
text-align: center;
padding: 40px !important;
}
.wrap {
width: 100%;
margin: 0 auto;
}
.left_col {
float: left;
width: 50%;
}
.right_col {
float: right;
width: 50%;
}
.right_col img {
width: 80%;
margin-top: 50px;
border: 2px solid black;
border-radius: 5px;
}
.left_col img {
width: 80%;
margin-top: 50px;
border: 2px solid black;
border-radius: 5px;
}
.aditional {
position:absolute;
top:100%;
width:100%;
background:#000;
display:none;
}
.aditional li {
color:#fff;
}
.navbar li:nth-child(2):before {
background: blue;
}
.navbar li:nth-child(3):before {
background: green;
}
.navbar li:nth-child(4):before {
background: red;
}
.navbar li:nth-child(5):before {
background: yellow;
}

答案 2 :(得分:1)
非常感谢Georgios这个!你让我走上了正确的轨道,我创建了一个额外的选择器,以便它只选择承包商!
这是新手的小提琴:
我简单地添加了:
.additional
Georgios的回答中的标签
.navbar li:nth-child(1):before {
background-color:red;
}
所以它现在看起来像这样:
.navbar .additional li:nth-child(3):before {
background-color: blue;
}