You need to enable JavaScript to run this app. 如何在CSS选择器中排除带有target=_blank属性的链接元素
优惠活动
大模型
产品
解决方案
定价
更多

如何在CSS选择器中排除带有target=_blank属性的链接元素

可以实现纯CSS排除,你之前写法失效是因为:not()伪类的使用规则错误。
:not() 伪类中如果是针对当前已选中的元素添加排除条件,不需要重复写元素选择器前缀,你尝试的:not(a[target="_blank"])重复声明了a标签,导致选择器匹配逻辑异常所以不生效。

正确写法是直接在原有选择器的排除序列中追加:not([target="_blank"])即可,修正后的完整代码如下:

.new-container a:not(.btn):not(.toc-list .cta-green):not(.cta-button-round-green):not(.cta-button-boxed-black):not([target="_blank"]) {
    background: linear-gradient(180deg,#FFB81C,#FFB81C);
    background-position: 0 100%;
    background-repeat: repeat-x;
    background-size: 1px .3rem;
    text-decoration: none;
    transition: background-size .2s;
    color: inherit !important;
}

如果页面存在target属性值大小写不统一、或者值前后带空格的非标准写法,可以替换为:not([target*="_blank" i]),开启大小写不敏感模糊匹配,兼容所有主流现代浏览器。

内容的提问来源于stack exchange,提问作者Gonras Karols

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 05:30:04