After creating a web component using Stencil that utilizes the shadow DOM and requires ignoring any externally added CSS (thanks to its own stylesheet), I employed the common fix for the component stylesheet:
:host {
all: initial;
}
This code effectively resets any base styles set on the page via the <style>
tag or an external stylesheet. Nonetheless, issues arise when dealing with inherited styles like font-size
from the :root
or html
elements, which override calculated values such as 1rem
, disregarding my specified font sizes in the component's CSS.
For instance, despite implementing the CSS reset mentioned above and aiming for a base size of 16px
, my development tools reveal that a font-size: 160px
value applied to the :root
is utilized when computing the final font size for an element designated with font-size: 0.875rem
.
https://i.sstatic.net/LERrN.png
I have delved into various resources regarding styles attributed to the :root
element, yet finding a solution remains elusive. Is there a method to override styles impacting relative values when they originate from the :root
element?