Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS unset not working as expected. How to resolve?

Tags:

html

css

I all: unset to unset all inheritance property but allow user agent stylesheet. How can I do it? As you can see in code it's disabling all styles even user agent stylesheets. How can I prevent user agent stylesheet disabling?

h1, h2 {
    color: red;
    font-size: 24px;
    font-weight: bold;
}
.editor_data * {
    all: unset;
}
<div class="main_block">
    <h2>Should be red</h2>
    <div class="editor_data">
    <h1><u><em><strong>Should be underlined, bold, italics, but not red</strong></em></u></h1>
    </div>
</div>
like image 658
Rushabh Shah Avatar asked Apr 12 '19 12:04

Rushabh Shah


People also ask

How do you unset a CSS style?

To unset the value of an element, unset keyword is used. The unset CSS keyword resets a property of an element to its inherited value if the property naturally inherits from its parent, or to its initial value if it does not inherit.

Can I use unset CSS?

unset can be applied to any CSS property, including the CSS shorthand property all .


1 Answers

Try the keyword revert instead of initial or unset

The revert keyword is useful for isolating embedded widgets or components from the styles of the page that contains them, particularly when used with the all property.

In user stylesheets, revert rolls back the cascade and resets the property to the default value established by the user-agent stylesheet.

MDN

h2 {
  color: red;
  font-size: 24px;
  font-weight: bold;
}

.editor_data * {
  all: revert;
}
<div class="main_block">
  <h2>Hello world!</h2>
  <div class="editor_data">

    <h1><u><em><strong>Hello world!</strong></em></u></h1>
  </div>
</div>
like image 157
Paulie_D Avatar answered Oct 16 '22 00:10

Paulie_D