Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate font-size through his parent in SASS?

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?

like image 574
JovStern Avatar asked Sep 21 '14 09:09

JovStern


People also ask

How do I calculate my font size?

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.

How do I calculate font size in CSS?

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).

Is font size inherited CSS?

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 .

How do I change relative font size to parent?

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.


1 Answers

You don't need SASS for it. Just use calc. Something like:

.h3 span {
    font-size: calc(100% - 2px);
}
like image 118
nir Avatar answered Oct 10 '22 11:10

nir