Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate empty vertical space in text

I have a span with CSS:

font-height = 120px; 
height = 120px;
line-height = 120px;

The text within it does not occupy the complete height(120px) of the span. Is there any way to calculate the offset of the text within the span from upper and lower boundaries?

Or is this an way to make the text touch the upper and lower boundaries of the enclosing span tag?

jsFiddle Link for reference.

like image 375
Manu Avatar asked Jan 23 '13 02:01

Manu


People also ask

How do I create a blank vertical space in HTML?

To include blank space in a document, you can use the <spacer> element. It is like an image, but actually, there isn't a picture there. You should specify <spacer> as one of the following types: horizontal, vertical, and block, which can be both horizontal and vertical.

How do I make vertical space 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 I make a DIV take all space vertically?

Another way of making a <div> fill the remaining space is to use the CSS position property. Just set the position to “absolute” to stretch the <div>.

How do I get rid of vertical space in overleaf?

The \vspace command adds vertical space. The length of the space can be expressed in any terms that LaTeX understands, i.e., points, inches, etc. You can add negative as well as positive space with an \vspace command. LaTeX removes vertical space that comes at the end of a page.


2 Answers

This visually does it without javascript:

#abc {
    margin: none;
    border: dotted 1px red;
    padding: 0;
    height: 120px;
    font-size:180px;
    line-height:120px;
    display:inline-block;
}

I think you need to use display:inline-block; and adjust the font size according to the actual font you use.

JsFiddle here

like image 192
frenchie Avatar answered Sep 21 '22 06:09

frenchie


The text is already taking 100% (120px) of the span height, you're forgetting other characters like "j" or "Á".

enter image description here

Try this html:

<span id="abc">jÁ / ABC</span>

and this css

#abc {
    margin: none;
    border: dotted 1px red;
    padding: 0;
    display:inline-block;
    /*****120px*****/
    height: 120px;
    font-size:120px;
    line-height:120px;
}

Test: http://jsfiddle.net/jTpfT/17/

like image 45
karacas Avatar answered Sep 20 '22 06:09

karacas