Get the font size of a div as a percentage of the size of that div's parent
<div id="parent" style= "width:100px; height:100px">
<div id="child" style="width:20px; height :20px; font-size:1vw">
Hello there
</div>
</div>
I admit my poor understanding of css is font-size:1em, which will be based on the element itself width percentage to resize "Hello".The width of the "child".
Assuming this is correct, is it possible to resize the "child"'s content to something like A percentage of the width of its parent element ("parent")?
uj5u.com enthusiastic netizens replied:
font-sizeem
Units are relative to the parent element's font size, not its width.
You cannot change the font size relative to the width of the parent element using only css.The closest option is to use vw
Unitsscale it relative to the viewport width.
uj5u.com enthusiastic netizens replied:
You can use % to change the font size relative to the font size of the parent element.I don't think you can use css to change the font size relative to the parent's width.If your parent is physical, then you can use vw.
0 Comments