gpt4 book ai didi

html - 悬停时选择最里面的类

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

当我在元素中进行递归时,我想选择最里面的类。
当您将鼠标悬停在 .comment 上时,只会显示此 div 的 .btn-reply
元素在 PHP 端生成(不包括在内,因为不相关)。

所以基本上如何选择大多数内部类元素而不是在父元素中选择相同的类元素(.comment > .btn-reply 也检查 SO Snippet)。

.comment {
border-top: 1px solid red;
border-left: 1px solid red;
padding-left: 10px;
}
.comment .comment-header {
height: 22px;
}
.comment .comment-header > .btn-reply {
display: none;
}
.comment:hover > .comment-header > .btn-reply {
display: inline;
}
button {
font-size: 12px;
}
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show oly me</button>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
</div>
</div>
</div>

最佳答案

.comment-header 上使用 hover,因为其他 .comment-headers 没有嵌套在其中:

.comment > .comment-header:hover > .btn-reply {
display: inline;
}

.btn-reply
{
display:none;
}

.comment {
border-top: 1px solid red;
border-left: 1px solid red;
padding-left: 10px;
}
.comment .comment-header {
height: 22px;
}

.comment > .comment-header:hover > .btn-reply {
display: inline;
}
button {
font-size: 12px;
}
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show oly me</button>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
<div class="comment">
<div class="comment-header">
<button class="btn-reply">Show only me</button>
</div>
</div>
</div>
</div>
</div>

关于html - 悬停时选择最里面的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28066086/

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