gpt4 book ai didi

html - 悬停 visibility 不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:22 24 4
gpt4 key购买 nike

我试图在悬停在 .box1 上时显示 div.user-options。但是当我将鼠标悬停在 .box1 上时,.user-options 不可见。可能是什么原因?

html:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="user-settings.css" type="text/css">
</head>
<body>

<div class="box">

<div class="box1"></div>

<div class="user-options">
<ul class="settings">
<li><a href="#">Profile</a></li>
<li><a href="#">blah blah</a></li>
<li><a href="#">Customization</a></li>
<li><a href="#">Logout</a></li>
</ul>
</div>

</div>

</body>
</html>

CSS:

 .box1{
width:50px;
height:50px;
background:orange;
}

.user-options{
background:orange;
visibility:hidden;
width:200px;
}

.settings{
list-style:none;
padding:0px;
}

.box .box1:hover .user-options{
visibility:visible;
}

.settings a{
text-decoration:none;
}

最佳答案

.box .box1:hover .user-options
^
^

那是一个descendant combinator . user-options 元素不是 box1 元素的后代,因此选择器不匹配。

他们是 sibling ,使用 sibling combinators 之一(例如 + )。

关于html - 悬停 visibility 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29984142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com