gpt4 book ai didi

css - 鼠标悬停和单击时 html div 的下拉效果

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:28 25 4
gpt4 key购买 nike

question 中的答案之一正在使用纯 css 方法:

HTML:

<div id="summary">Sample</div>
<div id="detail">Detail of this summary</div>

CSS:

> #summary:hover + #detail, #detail:hover {   display: block; }
> #detail { display: none; }

我的问题是我们如何将点击事件包含在像开关按钮一样的地方?

最佳答案

使 #summary div 成为 anchor 并在其上添加样式。

#summary:hover+#detail,
#detail:hover {
display: block;
}

#detail {
display: none;
}

#summary:focus+#detail,
#detail:focus {
display: block;
}
<a id="summary" href="javascript:void(0);">Sample</a>
<div id="detail">Detail of this summary</div>

.summary:hover+.detail,
.detail:hover {
display: block;
}

.show.detail {
display: block;
}

.detail {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="wrapper">
<a class="summary" href="javascript:void(0);">Sample1</a>
<div class="detail">Detail of this summary</div>
</div>
<div class="wrapper">
<a class="summary" href="javascript:void(0);">Sample2</a>
<div class="detail">Detail of this summary</div>
</div>

<div class="wrapper">
<a class="summary" href="javascript:void(0);">Sample3</a>
<div class="detail">Detail of this summary</div>
</div>

<script>
$(".summary").on("click", function() {
$(this).next().toggleClass("show");
})
</script>

关于css - 鼠标悬停和单击时 html div 的下拉效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50997365/

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