gpt4 book ai didi

css - 悬停div时显示ul :after

转载 作者:行者123 更新时间:2023-11-28 12:05:49 25 4
gpt4 key购买 nike

当鼠标悬停在 div:after 生成的箭头上时,我试图显示 ul。我该如何实现?

.select-wrapper {
position: relative;
width: 250px;
-webkit-box-sizing: border-box;
}
.select-wrapper:after {
content: "\25BC";
display: block;
}
<div class="select-wrapper">
<span>Select an option</span>
<ul>
<li>Item-1</li>
<li>Item-2</li>
</ul>
</div>

当鼠标悬停在箭头上时,我想显示元素。

enter image description here

enter image description here

最佳答案

在我看来,像 :after 这样的伪类是不可能的。要么为箭头创建一个附加元素,要么只使用整个 select 元素。

.select-wrapper {
position: relative;
width: 250px;
-webkit-box-sizing: border-box;
}
.select-wrapper:after {
content: "\25BC";
display: block;
position: absolute;
left: 0;
top: 20px;
}
.select-wrapper ul {
display: none;
}
.select-wrapper:hover ul {
display: block;
}
<div class="select-wrapper">
<span>Select an option</span>
<ul>
<li>Item-1</li>
<li>Item-2</li>
</ul>
</div>

更新:精确定位箭头

.select-wrapper {
position: relative;
width: 250px;
-webkit-box-sizing: border-box;
}
.arrow {
display: inline-block;
width: 0;
height: 0;
border-top: 8px solid #000;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
}
.arrow ul {
display: none;
position: absolute;
top: 100%;
left: 0;
}
.arrow:hover ul {
display: block;
}
<div class="select-wrapper">
<span>Select an option</span>
<div class="arrow">
<ul>
<li>Item-1</li>
<li>Item-2</li>
</ul>
</div>
</div>

关于css - 悬停div时显示ul :after,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39741469/

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