gpt4 book ai didi

CSS 属性选择器不起作用

转载 作者:行者123 更新时间:2023-12-04 21:15:56 24 4
gpt4 key购买 nike

我尝试选择红色段落并为其应用边框。为什么这段代码不起作用?

p[color="red"] {
border: 1px solid black;
}
<p style="color: green;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>
<p style="color: yellow;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>
<p style="color: lime;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>
<p style="color: darkgray;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>
<p style="color: red;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>
<p style="color: cyan;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>
<p style="color: indigo;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Repudiandae, provident, nam, et, consectetur molestiae aspernatur ratione placeat dignissimos odio cum non eveniet adipisci voluptas doloribus fugiat maiores odit sint repellat.</p>


我错过了什么吗?

fiddle : https://jsfiddle.net/kLx1gcq0/

最佳答案

[]是一个属性选择器,所以你必须选择 style属性如:

p[style*="color: red"] {
border: 1px solid black;
}

JSFiddle Demo *=如果属性包含指定的字符串,则选择元素。关于 CSS 选择器的优秀文章可以 be found here .

这有效,但前提是有空格。如果你不知道它是否会有空格,你可以这样做:
p[style*="color: red"],
p[style*="color:red"] {
border: 1px solid black;
}

关于CSS 属性选择器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34375075/

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