Is there a way to tell an html element to ignore any stylesheets?

后端 未结 7 1959
忘了有多久
忘了有多久 2020-12-03 10:15

I\'m attempting to add a drop down to a page that already has a global \"select\" style. Is there a way to tell the new select list to ignore the global style? There\'s ab

7条回答
  •  天命终不由人
    2020-12-03 10:47

    What I usually do in this situation is add a unique class to the new element; in this case something like this will work:

    
    

    and then in the stylesheet, find the global rule and add a :not() pseudoclass to differentiate:

    select:not(.i-am-unique) {
        /* global rules */
    }
    
    select.i-am-unique {
        /* unique rules */
    }
    

    This requires minimal code updates, with only 1 class added in your HTML markup, one CSS selector tweaked, and 1 new declaration block for the unique element. Here is an example.

    In addition, :not() is supported by a wide swath of browsers, even IE9+ and Safari 3.2+.

提交回复
热议问题