CSS使用:不是带CLASS的ID

 姿萱俊达俊宏 发布于 2023-02-13 14:04

是否有人知道如何使用CSS选择器:not()作为#some_id:not(.any_class_name)

代码看起来好像是正确的,但它不起作用.没有not选择器还有另一种方法吗?我在网上找不到任何东西.

我正在制作一个Web应用程序,其中包含多个页面,但有几个页面有div id=some_id.我以为我必须通过any_class_name使用上面的CSS代码添加一次来添加特定的CSS来解决问题,但它不起作用.

1 个回答
  • 我相信你正在扭转选择者.您有一些相同的元素class,但您想过滤掉具有特定元素的元素ID.在这种情况下:

    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及更早版本不支持此选择器.

    2023-02-13 14:06 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有