Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Text centered inside a DIV

Tags:

html

css

I am trying to achieve something and can't manage to do so.

I have a div with fixed HEIGHT & WIDTH. I want the text to be centered vertically.

up till now I managed to do so:

<div>
   <a>this is a long text</a>
</div>

and it will look like this

-------------
This is a long
    text
-------------

which is great

But if the line won't wrap it will look like this

------------
This is short

-------------

.the-div
{
height:29px;
line-height:14px !important;
}

.the-a
{
font-size:12px;
}

I need this to be valigned as well!

I tried using line-height and to play with is with JS to understand if its wrapping or not and then changing the line-height accordingly

Thanks for the help

like image 671
Himberjack Avatar asked Dec 02 '25 06:12

Himberjack


1 Answers

try this example

http://jsfiddle.net/fcalderan/3HBC4/1/


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!