Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't the CSS property 'line-height' letting me make tight line-spaces in Chrome?

Tags:

css

minimum

I have a paragraph tag that I defined elsewhere with a line height of 15px, and I have another paragraph tag further down the page where I want to make the line height around 10px. Funny thing is, it won't let me get down to 10px or anything smaller than that, but when I set it to 25px or higher, the line-height property seems to be working.

I checked the relevant CSS (all hand-coded) via the Chrome browser's web developer tools (Chrome's version of Firefox's Firebug) and couldn't find anything relevant. Is there a common CSS bug that prevents me from shrinking the line-height beyond a certain minimum amount?

like image 860
Simon Suh Avatar asked Sep 15 '11 01:09

Simon Suh


People also ask

How do I fix the spacing between lines in CSS?

Use the line-height property in CSS to do so. Browsers by default will create a certain amount of space between lines to ensure that the text is easily readable. For example, for 12-point type, a browser will place about 1 point of vertical space between lines.

How do you change the line height in CSS?

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.

What is a good line height CSS?

While there is no perfect line height, a good rule of thumb is to set it at approximately 150% of the font size. While there is no perfect line height, a good rule of thumb is to set it at approximately 150% of the font size.


2 Answers

I've noticed in both Firefox and Chrome that if you set the HTML5 doctype there's a minimum line-height for inline elements. For block elements you can set the line-height to whatever you want, even make the lines overlap.

If you don't set the HTML5 doctype, there's no minimum line-height for either block or inline elements.

like image 156
mhenry1384 Avatar answered Sep 22 '22 01:09

mhenry1384


I ran into the same issue, worked well with:

.element { display: block; line-height: 1.2; } 
like image 35
Nitish Avatar answered Sep 22 '22 01:09

Nitish