javascript - 悬停时为列表中的兄弟李项目设置样式
问题描述
基本上我有一个项目列表,当我将鼠标悬停在最后一个项目上时,我希望所有其他项目也更改其背景颜色。到目前为止,我尝试了一些解决方法,但没有成功。
<ul class ='profile'>
<li> item 1 </li>
<li> item 2 </li>
<li> item 3 </li>
</ul>
ul.profile > li:nth-child(3):hover {
background-color: red;
}
解决方案
试试这个:
ul.profile:hover > li:not(:hover) {
background-color: yellow;
}
ul.profile > li:nth-child(3):hover {
background-color: red;
}
推荐阅读
- java - 从左到右翻译布局
- android - 在 android 上将画布动画录制为实时视频
- javascript - 选择要插入到父输入字段的模态数据-Javascript、php、html
- mysql - 数据库表中的更新操作问题
- javascript - Eventlistners 和数据获取是 useEffect
- swift - 如何计算 Swift 中字符串中前导空格的数量?
- javascript - Socket 经常向客户端发送数据
- c - 在 C 中用 uint8_t 表示布尔值
- python - 在具有相同名称python XML的特定元素之间获取数据
- asp.net-core - 如何将具有动态 HTML 的 Razor Pages 中的多个实体添加到可编辑实体?