gpt4 book ai didi

html - 在整个页面上显示第一个特定元素

转载 作者:搜寻专家 更新时间:2023-10-31 22:37:46 25 4
gpt4 key购买 nike

我试图只显示第一个元素并隐藏所有其他元素。

这是一个例子:

<style>
h1 {
display: none;
}

h1:first-of-type{
display: block;
}
</style>

<body>
<div class="content">
<h1>Test</h1> <!-- only this one should be visible -->
123
</div>
<div class="content">
<h1>ABC</h1>
def
</div>
</body>

有没有不用JS的解决方案?

最佳答案

h1 上使用 :first-of-type 是行不通的,而是在第一个 .content 上使用它h1。像这样:

h1 {
display: none;
}

.content:first-of-type h1 {
display: block;
}

    h1 {
display: none;
}

.content:first-of-type h1{
display: block;
}
    <div class="content">
<h1>Test</h1>
123
</div>
<div class="content">
<h1>ABC</h1>
def
</div>

关于html - 在整个页面上显示第一个特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44821537/

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