gpt4 book ai didi

html - CSS :not() selector - Hide everything from body except one div

转载 作者:行者123 更新时间:2023-12-01 23:47:10 25 4
gpt4 key购买 nike

是否可以用 CSS 隐藏所有 body 内部元素
除了介绍类和他的子元素?

body *:not(.intro > *) {
opacity: 0;
}
<body>

<h1>Welcome to My Homepage</h1>

<div class="intro">
<p id="firstname">My name is Donald.</p>
<p id="hometown">I live in Duckburg.</p>
</div>

<p>My best friend is Mickey.</p>

</body>

最佳答案

除了.intro 之外,您可以隐藏body 的所有直接子元素。不透明度将应用于一个元素及其所有子元素。

body>*:not(.intro) {
opacity: 0;
}
<body>
<h1>Welcome to My Homepage</h1>
<div class="intro">
<p id="firstname">My name is Donald.</p>
<p id="hometown">I live in Duckburg.</p>
</div>
<div class="outro">
<p id="firstname">My name is Mickey.</p>
<p id="hometown">I live in Mickeyburg.</p>
</div>
<p>My best friend is Mickey.</p>
</body>

关于html - CSS :not() selector - Hide everything from body except one div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64004130/

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