【发布时间】:2019-07-19 16:03:14
【问题描述】:
这个问题在条件 CSS 中可能更简单。
我有五行包含一些内容,根据某些条件,我添加了一个名为 'previous' 的类来显示不同的背景颜色。
当我将鼠标悬停在上一个课程内容时,我得到了透明的背景,这不好。
我想显示相同的背景颜色(灰色),即使它被悬停。
所以,我尝试了下面的代码并尝试在 css 中使用 :has 条件,如果它有以前的类,则将悬停颜色更改为灰色。但它没有用。
我的期望是即使悬停也有相同的背景颜色。
有人可以帮我解决这个问题,因为我只需要 CSS/SCSS 的解决方案。不是来自 javascript。
.previous {
background-color: grey;
}
.row:hover {
background-color: transparent;
:has(.previous) {
background-color: grey;
}
}
<div class="row">Some Content 1</div>
<div class="row previous">Some Content 2</div>
<div class="row">Some Content 3</div>
<div class="row previous">Some Content 4</div>
<div class="row">Some Content 5</div>
【问题讨论】: