gpt4 book ai didi

html - CSS - 选择后代元素的后代元素

转载 作者:行者123 更新时间:2023-11-28 17:12:06 25 4
gpt4 key购买 nike

如果我有 HTML 代码,

<div class="group">
<p>This paragraph has <code>inline code that should be selected</code>.</p>
<code>This is a block of code that should not be selected.</code>
</div>

<div class="other">
<p>This paragraph has <code>inline code that should NOT be selected</code.</p>
</div>

如何只选择 p 元素中的 code 元素,这些元素是“group”类描述的元素的后代?我现在想让它保持相当通用,所以如果我在 em 元素中有一个 code 元素,而该元素在 p 元素,我还是想选择它。

我一直遇到这个问题,所以我想知道它是否可能,而不是其他实际上不解决选择另一个后代元素的后代元素的方法。但是,我是 HTML 和 CSS 的新手,所以如果我认为所有这些都是错误的,我想知道。

最佳答案

您只需使用两个 descendant combinators在你的选择器中。

.group p code

关于html - CSS - 选择后代元素的后代元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45259427/

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