CSS使用:不带ID的CLASS [英] CSS use :not ID with CLASS
问题描述
有人知道如何使用CSS选择器:not()
为 #some_id:not(.any_class_name)
?
Does someone know how to use the CSS selector :not()
as #some_id:not(.any_class_name)
?
代码看起来好像是正确的,但它不工作。有没有其他方法没有不
选择器?我在互联网上找不到任何东西。
The code looks as if it is right, but it doesn't work. Is there another way without the not
selector? I couldn't find anything on the Internet.
我正在制作一个包含多个网页的网络应用程序,但有几个网页有 id = some_id
。我想我不得不添加特定的CSS通过添加 any_class_name
一次使用上述CSS代码解决问题,但它不工作。
I am making a web application, which includes more than one page, but several pages have divs with id=some_id
. I thought I had to add specific CSS by adding any_class_name
one time using the above CSS code solve the problem, but it doesn't work.
推荐答案
我相信你是选择器。您有一些具有相同 class
的元素,但是您想要筛选出具有特定 ID
的元素。在这种情况下:
I believe that you are reversing the selectors. You have some elements with the same class
, but you want to filter out an element with an specific ID
. In that case:
HTML:
<p class="someclass">hello</p> <!-- will be targeted by css below, thus green -->
<p class="someclass" id="some-id">hi</p> <!-- will not be targeted by css below -->
CSS:
.someclass:not(#some-id){ color: green; }
/* selects all elements with classname 'someclass',
but excludes the one that has also has an id of 'some-id' */
正如@secretSquirrel指出的,请注意浏览器兼容性:Internet Explorer 8及更早版本不支持此选择器。
And as @secretSquirrel pointed out, note the browser compatibility: this selector is not supported by Internet Explorer 8 and older.
这篇关于CSS使用:不带ID的CLASS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!