gpt4 book ai didi

html - 影响所有相同起始名称样式的 CSS 前缀范围

转载 作者:太空宇宙 更新时间:2023-11-03 21:36:39 26 4
gpt4 key购买 nike

?是否可以为影响所有以相同前缀开头的 html 元素的样式定义名称请不要偏离类别或标签......请不要使用 SASS、LESS 或类似的处理器请注意问题在于定义样式,而不是使用选择器进行过滤

像这样(星号*可以作为通配符)->

in CSS <style> section
#prfxStyle1* { background-color: #ABCDEF; }

in <HTML> section
<div id="prfxStyle1Metals"> ... </div>
<div id="prfxStyle1Plastics"> ... </div>
<div id="prfxStyle1Organics"> ... </div>

最佳答案

“开头为”选择器仅适用于属性选择器。

因此,在这种情况下,要找到以 prfxStyle1 开头的 id,您需要执行以下操作:

[id^="prfxStyle1"] {
/* styles */
}

通过属性选择器,您可以定位到任何内联元素定义的属性(包括自定义属性):

<div attribute="value">

可能的属性选择器:(来自 MDN docs)

[attr]
Represents an element with an attribute name of attr.

[attr=value]
Represents an element with an attribute name of attr and whose value is exactly "value".

[attr~=value]
Represents an element with an attribute name of attr whose value is a whitespace-separated list of words, one of which is exactly "value".

[attr|=value]
Represents an element with an attribute name of attr. Its value can be exactly “value” or can begin with “value” immediately followed by “-” (U+002D). It can be used for language subcode matches.

[attr^=value]
Represents an element with an attribute name of attr and whose value is prefixed by "value".

[attr$=value]
Represents an element with an attribute name of attr and whose value is suffixed by "value".

[attr*=value]
Represents an element with an attribute name of attr and whose value contains at least one occurrence of string "value" as substring.

关于html - 影响所有相同起始名称样式的 CSS 前缀范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26042797/

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