Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove white space above and below large text in an inline-block element

Say I have a single span element defined as an inline-block. It's only contents is plain text. When the font size is very large, you can clearly see how the browser adds a little padding above and below the text.

HTML:

CSS:

span {    display: inline-block;    font-size: 50px;    background-color: green;  }    ​
<span>BIG TEXT</span>

Looking at the box model, it's clear the browser is adding padding inside the content edge. I need to remove this "padding", one way is to simply alter the line-height, as with:

http://jsfiddle.net/7vNpJ/1/

This works great in Chrome but in Firefox the text is shifting towards the top (FF17, Chrome 23, Mac OSX).

Any idea of a cross-browser solution? Thanks!

like image 527
MusikAnimal Avatar asked Dec 27 '12 20:12

MusikAnimal


People also ask

How do I remove white space in HTML?

We can also remove white space by setting parent element font-size to 0 and child elements font-size to 17px .

How do I remove spaces from text in CSS?

In this CSS word-spacing example, we have removed 3px of space between the words by setting a -3px value for the word-spacing property. This removes some of the word spacing that has been added by the selected font.


1 Answers

It appears as though you need to explicitly set a font, and change the line-height and height as needed. Assuming 'Times New Roman' is your browser's default font:

span {   display: inline-block;   font-size: 50px;   background-color: green;   /*new:*/   font-family: 'Times New Roman';   line-height: 34px;   height: 35px; }
<span>     BIG TEXT </span>
like image 91
karacas Avatar answered Sep 26 '22 23:09

karacas