【发布时间】:2019-11-09 01:00:27
【问题描述】:
我希望在将鼠标悬停在每个项目上时移除红色边框。
您可以从我附在此处的jsFiddle 中看到。它只适用于左侧的第一个 div,也适用于右侧的其余 div。
我这样做的原因是因为我希望它灵活,以便我可以在 HTML 上添加或删除而不影响 CSS 部分。
.wrapper {
height: 100px;
display: flex;
background-color: lightblue;
}
.item {
background-color: lightgreen;
flex: 0 0 15%;
}
.item-left + .item-right {
margin-left: auto;
}
.item-left{
border-left:1px solid red;
}
.item-left:first-of-type{
border:none;
}
.item-left:last-of-type{
border-right:1px solid red;
}
.item-right{
border-left:1px solid red;
}
.item:hover{
/* box-shadow: x y blur spread color; */
box-shadow:0px 0px 0px -1px rgba(0, 0, 0, 0.2), 0px 0px 10px 0px rgba(0, 0, 0, 0.19);
z-index:1;
}
.item:hover + .item.item-left, .item.item-right {
border:none;
}
<div id="bottom" class="bottom">
<div class="wrapper">
<a class="item item-left">
<div class="item-label">Left</div>
</a>
<a class="item item-left">
<div class="item-label">Left</div>
</a>
<a class="item item-left">
<div class="item-label">Left</div>
</a>
<a class="item item-right">
<div class="item-label">Right</div>
</a>
<a class="item item-right">
<div class="item-label">Right</div>
</a>
<a class="item item-right">
<div class="item-label">Right</div>
</a>
</div>
</div>
感谢您的帮助!
【问题讨论】:
-
我只能在小提琴的第二个和第三个元素上看到红色边框。那么移除不存在的红色边框是什么意思?
-
我希望将鼠标悬停在第二个和第三个边框上时将其删除。就像您将鼠标悬停在第一个项目上一样。
-
你需要纯css解决方案?
-
是的。纯 CSS。从上面的脚本可以看出,它只适用于它之后的元素,而不是前一个元素。
-
@Zze 在这种情况下,两组项目之间存在间隙,这使兄弟选择器方法变得复杂。