CSS exclude a tag from * selector

有些话、适合烂在心里 提交于 2021-02-16 18:22:25

问题


I'm working on a small CSS style sheet. I want to restyle all the Text content to a Roboto font. I wrote this code below : *{font-family:Roboto !important;}

Now How to select everything aside from the icon( I want to exclude the icons (i) tag from my selector, some do useFontAwesome some use other icon fonts)

So is there something that I can add to the * selector to select everything aside fro the icons?


回答1:


Put a negation for the classes that you don't want to apply the style:

For example:

*:not(.fa) {
    font-family: Roboto !important;
}

Usually the icons are in "i" elements, you could do the following as well to affect any icons:

*:not(i) {
    font-family: Roboto !important;
}

But using "i" elements is not mandatory, and there could be icons that are not as "i" tags, as well as normal text as "i" tags (although this is very unusual)

Also, take into account that using "!important" is not a good practice, especially with a rule so generic.



来源:https://stackoverflow.com/questions/61001451/css-exclude-a-tag-from-selector

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!