简体   繁体   English

CSS *选择器,但不包括特定标签

[英]CSS * selector but exclude a particular tag

Background 背景

So I found this line of code in our Ext JS's css which removes focus for every element in webkit. 因此,我在Ext JS的 css中找到了这行代码,从而消除了webkit中每个元素的关注。 Unfortunately it has been almost 2 years and they still haven't addressed their TODO. 不幸的是,已经快两年了,他们仍然没有解决他们的待办事项。

    // TODO: remove outline from individual components that need it instead of resetting globally
.#{$prefix}webkit {
    * {
        &:focus {
            outline:none !important;
        }
    }
}

which compiles to 编译成

.x-webkit *:focus {
  outline: none !important;
}

What this does is take away the browsers default focus (UA styles) on links so when the user tabs to an anchor tag they have no UI indication that they are on the tag. 这样做是为了消除浏览器在链接上的默认焦点(UA样式),因此当用户使用Tab键定位到锚标记时,他们没有UI指示它们就在标记上。 I want to use native browser behavior so I don't want to override the a:focus in particular and using initial doesn't work. 我想使用本机浏览器行为,所以我不想特别覆盖a:focus ,并且使用initial无效。 Also removing the entire style causes UI components to handle their focus UI differently which is not acceptable. 同样,删除整个样式会使UI组件以不同的方式处理其焦点UI,这是不可接受的。

tldr tldr

What is the best approach for applying a style to all tags except a certain tag(s). 将样式应用于除某些标签之外的所有标签的最佳方法是什么? I know I can make a selector that has all of the tags except the tag I don't want but that is tedious, is that really the best approach ? 我知道我可以使选择器具有除我不想要的标签之外的所有标签,但那很乏味,这真的是最好的方法吗? If so is there a list of valid UI tags for HTML ? 如果是这样,那么是否存在HTML的有效UI标记列表?

You could use the CSS :not selector, and apply a style to all descendants of .x-webkit except the tag(s) you want to exclude: 您可以使用CSS :not选择器,并向.x-webkit所有后代应用样式,但要排除的标记除外:

 .x-webkit *:not(p):not(em) { color: red; } 
 <div class="x-webkit"> <div>red</div> <ul><li>red</li></ul> <p> Not red<br> <strong>red</strong><br> <em>Not red</em> </p> <table><tr><td>red</td></tr></table> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM