I have several heading in my scss file:
h1{font-size:18px}
h2{font-size:16px}
h3{font-size:12px}
and in my my index.html i've got this:
<h1>Heading <span>Secondary text</span></h1>
<h2>Heading <span>Secondary text</span></h2>
<h3>Heading <span>Secondary text</span></h3>
I would like to calculate the font-size of the SPAN tag, lats say.. font-size equal minus 2px to the heading that contains him?
A font is often measured in pt (points). Points dictate the height of the lettering. There are approximately 72 (72.272) points in one inch or 2.54 cm. For example, the font size 72 would be about one inch tall, and 36 would be about a half of an inch.
For example, suppose the font-size of the <body> of the page is set to 16px . If the font-size you want is 12px , then you should specify 0.75em (because 12/16 = 0.75). Similarly, if you want a font size of 10px , then specify 0.625em (10/16 = 0.625); for 22px , specify 1.375em (22/16).
When you set font-size on an element, the element certainly does not inherit font size. This is about the effect of the relative nature of the em unit. Should you have set a:link{font-size:1.5em;} for example, you can easily override it for links inside paragraphs without using ! important .
It is related to the font size of the parent container. One em (1em) is equal to the current font size. So for example, if the parent element has the font size of 16px than 1em is equal to 16px, 2em is equal to 32px, and so on. Making your design responsive becomes much easier if you use em units instead of px.
You don't need SASS for it. Just use calc. Something like:
.h3 span {
font-size: calc(100% - 2px);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With