可以用css做到这一点吗?将鼠标悬停在其中一个元素上时:text2、text3、text4、text1 将颜色更改为“小麦”
.list {
display: flex;
}
.item {
margin-right: 15px;
padding: 10px;
background: wheat;
}
.item:first-child {
background: #ccc;
}
.item:hover {
background: #ccc;
}
<div class="list">
<div class="item">text1</div>
<div class="item">text2</div>
<div class="item">text3</div>
<div class="item">text4</div>
</div>
从视觉上看,如果您以相反的顺序排列 DOM 中的元素并应用,则可以做到这一点
flex-direction: row-reverse你想要的 CSS 是不可能的,但是这个任务可以使用 JS 来解决。不需要包含文件
style.js,把代码写在标签里面<script></script>