I was expecting my paragraph to inherit from the parent style if the css variable was undefined. Instead it inherited from the user agent stylesheet. What am I missing?
.myapp p {
color: inherit;
font-family: var(--BodyFontFamily, var(--BodyTextFontFamily, Arial,Verdana,Helvetica,sans-serif));
font-size: var(--BodyFontSize, 20px);
line-height: var(--BodyLineHeight, 24px);
}
.text-overlay p {
font-size: var(--OverlayBodyFontSize);
font-weight: var(--OverlayBodyFontWeight);
font-family: var(--OverlayBodyFontFamily);
line-height: var(--OverlayBodyLineHeight);
}
The reason I was anticipating inheritance was because the paragraph did inherit from .myapp p when the overriding style block was empty.
.text-overlay p {
/* inheritance happened :) */
}
i've tried using inherit as a default value
.text-overlay p {
font-size: var(--OverlayBodyFontSize, inherit);
}
i've tried adding the parent selector to my overriding style block
.myapp .text-overlay p {
font-size: var(--OverlayBodyFontSize)
}
i did read this post but their situation was a little different. CSS Variables inheritance and fallback
working example of the actual situation
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
:root {
--BodyFontSize: 30px;
--BodyLineHeight: 20px;
}
</style>
<style>
.myapp p {
font-size: var(--BodyFontSize, 20px);
line-height: var(--BodyLineHeight, 24px);
}
.text-overlay p {
/* inheritance happens :)*/
}
/* uncomment this to see the user agent style get inherited */
/*
.text-overlay p {
font-size: var(--OverlayBodyFontSize);
line-height: var(--OverlayBodyLineHeight);
} */
</style>
</head>
<body>
<div class="myapp">
<p>Default Font Styling</p>
<div>
<div class="text-overlay">
<p>Expected Style Override To Inherit From .myapp rather than the user agent. Because --OverlayBodyFontSize and --OverlayBodyLineHeight are undefined</p>
</div>
</div>
</div>
</body>
</html>