[英]Targeting specific class when there are more than one element with the same class?
[英]How to modify a class when a specific class exists on the same element?
所以我在这里有我的(在这里简化了)bootstrap navbar。
<nav class="navbar">
<ul class="navbar-nav">
<li><a href="#">foo</a></li>
</ul>
</nav>
.navbar-fixed-top {
height: 100px;
}
.navbar-nav >li >a {
line-height: 100px
}
我只想在将类.shrink
添加到nav
时缩小navbar
。 非常简单,只需将以下内容添加到我的CSS中:
.shrink {
height: 80px;
}
问题是:该line-height
的.navbar >li >a
保持100px
-有没有办法我只能与CSS的影响呢?
大概是这样吗?
.navbar {
height: 100px;
}
.navbar.shrink {
height: 80px
}
.navbar > .navbar-nav > li > a {
line-height: 100px
}
.navbar.shrink > .navbar-nav > li > a {
line-height: 80px
}
您可以尝试:
.shrink a {
line-height: <whatever>;
}
这会将您想要的样式应用于带有缩小类的元素中包含的元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.