gpt4 book ai didi

html - 我怎样才能只选择第一个不是脚本标签的普通兄弟?

转载 作者:太空宇宙 更新时间:2023-11-04 01:22:54 24 4
gpt4 key购买 nike

我的结构/风格类似于下面的代码片段。我试图将第一个不是脚本标记的元素作为目标,但不知道它是什么类型的元素。 (我继承了一个旧的代码库,部分不会由我更新。)

如您所见,我尝试了 header ~ :not(script):first-of-type 但它选择了所有不是脚本标记的一般兄弟。

我还尝试了 header ~ :not(script):first-child,但没有选择任何内容。有什么想法吗?

header ~ :not(script):first-of-type{
color: red;
}
<body>
<header>This is the header</header>
<script>// This script tag may or may NOT be present</script>
<section>These are the section tags, <strong>that may also be DIV tags</strong> (or some other wrapper) in some cases</section>
<footer>This is the footer</footer>
</body>

最佳答案

没有办法只用一行 CSS(我知道),但请尝试使用相邻的选择器:)

header + *:not(script) { color: red; }
header + script + * { color: red; }
<body>
<header>This is the header</header>
<script>// This script tag may or may NOT be present</script>
<section>These are the section tags, <strong>that may also be DIV tags</strong> (or some other wrapper) in some cases</section>
<footer>This is the footer</footer>
</body>

关于html - 我怎样才能只选择第一个不是脚本标签的普通兄弟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48715686/

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