When working on designing in the browser with CSS, it is important to note that the font-size
set on a <span>
tag is relative and based on the <p>
tag.
Exploration
After conducting some research, I came across a recent question related to nested <span>
inside a <p>
tag that discusses font size differences. This can be found at "Nested <span>
inside a <p>
tag giving different font size" referencing insights from CSS-Tricks:
"The em unit is a relative unit based on the computed value of the font size of the parent element. Child elements rely on their parent to determine their font size."
Despite my best efforts, I could not find a conclusive answer to my query through searches:
- [css] total em size
- [css] em size
- CSS: 100% font size - 100% of what?
Another related question did not provide the answers I was seeking:
- Why would the height increase with a smaller font size?
Main Inquiry
If we consider the following HTML:
<p class="foo"><span class="bar">This month is March.</span></p>
And corresponding CSS:
.foo {
font-family:"Proxima Nova Rg", sans-serif;
font-size:0.833em;
font-style:normal;
font-variant:normal;
font-weight:normal;
}
.bar {
font-family:"Proxima Nova Rg", sans-serif;
font-size:0.8em;
font-style:normal;
font-variant:normal;
font-weight:normal;
}
What would be the actual height of the text "This month is March." considering the applied CSS font sizes within the <p>
and <span>
tags?
I am interested in understanding if there is a formula or method to calculate the final font size when both the <p>
and <span>
tags have specific heights assigned.