Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set line height in Html <p> to make the html looks like a office word when <p> has different font sizes

Tags:

html

css

fonts

How to set the line height in ONE html tag <p>, when this <p> have two different font sizes?

If I set the <p style="line-height:120%"> .... </p>, then the whole <p> will only have one line height.

But I hope it will behave like the Microsoft Office Word/(and Google Doc). i.e.: different contents with different font sizes will have different line height.

Is it possible for <p> to achieve that effect? Or do I have to do this line by line, like Google Doc? Is there any easier way?

like image 965
sky609 Avatar asked Jul 05 '11 14:07

sky609


People also ask

How do you set line height in HTML?

The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text. On block-level elements, it specifies the minimum height of line boxes within the element. On non-replaced inline elements, it specifies the height that is used to calculate line box height.

How do I change font size in HTML p tag?

How to Change Font Size in HTML. To change font size in HTML, use the CSS font-size property. Set it to the value you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a paragraph, heading, button, or span tag.

How do you change text width and height in HTML?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.

What is standard line height in HTML?

The default line height in most browsers is about 110% to 120%. This is a paragraph with a smaller line-height. This is a paragraph with a smaller line-height. This is a paragraph with a bigger line-height.


1 Answers

Actually, you can achieve this pretty easy. Simply specify the line height as a number:

<p style="line-height:1.5">
    <span style="font-size:12pt">The quick brown fox jumps over the lazy dog.</span><br />
    <span style="font-size:24pt">The quick brown fox jumps over the lazy dog.</span>
</p>

The difference between number and percentage in the context of the line-height CSS property is that the number value is inherited by the descendant elements, but the percentage value is first computed for the current element using its font size and then this computed value is inherited by the descendant elements.

For more information about the line-height property, which indeed is far more complex than it looks like at first glance, I recommend you take a look at this online presentation.

like image 65
Pavel Vladov Avatar answered Oct 03 '22 06:10

Pavel Vladov