gpt4 book ai didi

html - CSS * :not(div p) does not select anything

转载 作者:技术小花猫 更新时间:2023-10-29 12:43:21 25 4
gpt4 key购买 nike

我有以下 HTML 代码:

<div>
<p> linux version</p>
<h1> new tool </h1>

还有一些应该选择 <h1> 的 CSS但不选择任何东西。

*:not(div p) {
font-family: sans-serif;
}

以下也不起作用:

*:not(div>p) {}

我有很多这样的<div> <p>在 HTML 中,而以下选择并应用字体:

div p {
font-family: sans-serif;
}

最佳答案

正如其他人在评论中所说:not选择器的用法是这样的:

E:not(s) - an E element that does not match simple selector s

在哪里

A simple selector is either a type selector, universal selector, 
attribute selector, class selector, ID selector, or pseudo-class.

所以如果你想让你的代码工作,你必须添加一个类到<p>您不想使用该字体系列设置样式的元素。

*:not(.classname) {
font-family: sans-serif;
}

或者:如果您需要将字体应用到所有元素 - 通常通过在 body 元素中设置它来完成,然后文档中的其他元素继承该规则。

然后你可以设置你的 <p> 的样式div 中的元素不同。

body
{
font-family: sans-serif;
}

div p
{
/* the special font-family that you need for paragraphs within a div */
}

关于html - CSS * :not(div p) does not select anything,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20771039/

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