How to remove all inherited and computed styles from an element?

前端 未结 2 1014
臣服心动
臣服心动 2021-01-12 18:27

The page has the following CSS:

input[type=text]
{
    display: inline; padding: 7px; background-color: #f6f6f6; font-size: 12px; letter-spacing: 1px; border         


        
2条回答
  •  感情败类
    2021-01-12 18:59

    Is there a certain way to do this

    There is no way to stop rules applying to an element if the selector matches.

    You can either

    • set every property you want to have a specific value (with a suitably specific selector and !important
    • move the element to a different document (which could then be loaded with, for example, an iframe).
    • remove the rule (and thus cause it to not apply to any element)
    • change the selector on the ruleset (so it doesn't match the element any more, you have to be careful to make sure it still selects elements you care about)

    other than getting the list of all computed styles and setting them empty?

    That wouldn't work. Most properties won't accept a blank value, so the rule would be invalid and ignored (thus causing the previous rule to apply again).

提交回复
热议问题