【发布时间】:2018-07-01 23:21:12
【问题描述】:
我正在使用唯一子选择器来显示特定的背景颜色,并使用悬停样式来显示不同的背景颜色。问题是当只有一个孩子时,我不希望悬停样式起作用。我该怎么做?
1) 没有红色背景,但是当我们悬停时它会变成绿色背景
.report p:only-child {
background: red;
}
.report p:hover {
background: green;
}
<div class="report">
<p>Test1</p>
<p>Test2</p>
</div>
2) 悬停时红色背景,但没有绿色背景
.report p:only-child {
background: red;
}
.report p:hover {
background: green;
}
<div class="report">
<p>Test1</p>
</div>
【问题讨论】:
标签: javascript html css hover