我有这个CSS& HTML到目前为止:
.divi:hover {
background: #01ba7c;
}
.divi:hover > p {
visibility: visible;
}
<div style="height: 100px; width: 100px; position: relative; left: 300px; top: 100px; border: 2px solid black;" class="divi">
<p style="visibility: hidden;">This is a test and better work!</p>
</div>
我想要的是文本仅在某人悬停包含p的div时出现。为什么这不起作用?所有这一切都是我的div背景改变我指定的颜色。 谢谢!
答案 0 :(得分:1)
这是一个选择器特定的问题,你的内联样式比任何样式表规则都强。
.divi {
height: 100px;
width: 100px;
position: relative;
left: 300px;
top: 100px;
border: 2px solid black;
}
.divi:hover {
background: #01ba7c;
}
.divi p {
visibility: hidden;
}
.divi:hover > p {
visibility: visible;
}
<div class="divi">
<p>This is a test and better work!</p>
</div>
答案 1 :(得分:1)
内联样式会覆盖样式表。
将<p style="visibility: hidden;">
更改为<p>
.divi:hover {
background: #01ba7c;
}
.divi > p{
visibility: hidden;
}
.divi:hover > p {
visibility: visible;
}
&#13;
<div style="height: 100px; width: 100px; position: relative; left: 300px; top: 100px; border: 2px solid black;" class="divi">
<p>This is a test and better work!</p>
</div>
&#13;