Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css line-height : number to px

am doing an automation tool which has to pick html css properties (font-color, size, etc..), and am done most of the part.Here the problem is, some case am getting the css property(line-height), line-height : 1.54 . Here for some purpose, i need to convert the number(1.54) to px value(like, line-height : 15px). So, Is it possible to do this calculation ?

like image 253
sibi Avatar asked Nov 16 '17 10:11

sibi


People also ask

What PX line is 1.5 height?

Again, we look to Google's Material Style Guide for the answer. Google runs a 1.5 line height for its body there, or 16px font size and a line-height of 24px.

What is 150% line-height?

line-height: 150% will take 150% of the element's computed font size to compute the line height, which is equivalent to multiply it by 1.5 .

How do you calculate line-height in CSS?

It takes the font-size value and multiplies it by 1.2 . Let's calculate the height of one line with the following example. We just have to do the following calculation: 16 * 1.5 = 24px. So we now know that our text will have a minimum height of 24px.

What is standard line-height pixels?

If your font size is 10px, your line height will be 3px, 5px, and 11px respectively. Alternatively, you can specify the “normal” keyword. This keyword specifies the use of the browser default. This value is usually around 1.2, depending on what browser the viewer is using.


1 Answers

Unitless line-height refers to the font-size of the element.

If your element has set font-size: 14px, do the simple math:

1.54 * 14px = 21.56px

You can get more information here:

https://developer.mozilla.org/en/docs/Web/CSS/line-height

like image 89
hsz Avatar answered Oct 13 '22 01:10

hsz