The only ways to prevent certain styles from being applied are:
- Removing these styles from the stylesheet
- Overriding them with the desired styles
Since you don't need the first way, it should be the second.
CSS3 introduces initial
both unset
keywords and all
shorthand property. So to undo some styles you can use
background: unset;
all: unset;
select[data-reset] {
all: unset;
}
<select data-reset>
<option>Option</option>
</select>
<select data-original>
<option>Option</option>
</select>
Run code
However, this will set the properties to their initial value . This initial value as defined in the specification is likely to be different from the default stylesheet used by browsers. So it won't work in practice.
Then, is there a way to restore the values from the user agent stylesheet? Not directly. However, you can just copy the styles from the default stylesheet.
all: unset;
select[data-reset] {
all: unset;
-moz-appearance: menulist;
-moz-user-select: none;
background-color: -moz-combobox;
border-color: threedface;
border-style: inset;
border-width: 2px;
box-sizing: border-box;
color: -moz-comboboxtext;
cursor: default;
display: inline-block;
font: ;
line-height: normal !important;
margin: 0;
overflow: -moz-hidden-unscrollable;
page-break-inside: avoid;
text-align: start;
text-indent: 0;
text-shadow: none;
white-space: nowrap !important;
word-wrap: normal !important;
writing-mode: horizontal-tb !important;
}
<select data-reset>
<option>Option</option>
</select>
<select data-original>
<option>Option</option>
</select>
Run code
But there is still a problem: the elements select
are being replaced, so their presentation is outside the scope of CSS. Then, by default, Firefox select
displays slightly differently than what the internal stylesheet says.
To get closer to the original view, you can use
border: 1px solid #7f9db9;
font: initial;
font-family: Tahoma;
font-size: 13.3333px;
So the complete code would be
all: unset;
-moz-appearance: menulist;
-moz-user-select: none;
background-color: -moz-combobox;
border: 1px solid #7f9db9;
box-sizing: border-box;
color: -moz-comboboxtext;
cursor: default;
display: inline-block;
font: initial;
font-family: Tahoma;
font-size: 13.3333px;
line-height: normal !important;
margin: 0;
overflow: -moz-hidden-unscrollable;
page-break-inside: avoid;
text-align: start;
text-indent: 0;
text-shadow: none;
white-space: nowrap !important;
word-wrap: normal !important;
writing-mode: horizontal-tb !important;
select[data-reset] {
all: unset;
-moz-appearance: menulist;
-moz-user-select: none;
background-color: -moz-combobox;
border: 1px solid #7f9db9;
box-sizing: border-box;
color: -moz-comboboxtext;
cursor: default;
display: inline-block;
font: initial;
font-family: Tahoma;
font-size: 13.3333px;
line-height: normal !important;
margin: 0;
overflow: -moz-hidden-unscrollable;
page-break-inside: avoid;
text-align: start;
text-indent: 0;
text-shadow: none;
white-space: nowrap !important;
word-wrap: normal !important;
writing-mode: horizontal-tb !important;
}
<select data-reset>
<option>Option</option>
</select>
<select data-original>
<option>Option</option>
</select>
Run code
Oriol
source
to share