Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text-align:center; doesn't work

Tags:

html

css

I have been messing around with the layout of my website and my text-align : center; stopped working that happened after i set all my divs position to relative to make the parent div change size when I add components to it with javascript.

Here are both of my CSS files:

You can see the new one in the JSfiddle link below.

jsFiddle: http://jsfiddle.net/2WvrV/

I also provide the code for the old website (which aligns the text properly) :

http://jsfiddle.net/fiddlerOnDaRoof/fQpjX/

the old HTML is very similar to the new version i just added the style="float:left;" in one of the divs

like image 555
Xitcod13 Avatar asked May 02 '12 05:05

Xitcod13


People also ask

Why text-Align Center doesn't work?

Short answer: your text isn't centered because the elements are floated, and floated elements "shrink" to the content, even if it's a block level element.

How do I force align text Center in HTML?

text-align and inline-block Simply add text-align center to parent div and set the child div display to inline-block. This will force our div to behave like inline element and therefore subjected text-align center.

How does text-Align Center work?

The text-align property with the value center is the most popular technique to center text in a div. Setting the line-height of your div to half of its height will align all of the text in it horizontally in the middle of the container (or width).


1 Answers

Anywhere you have float:left; in your CSS, add width: 100%; after it. Floating will kill your desired center alignment.

Also, add text-align: center; to #login

like image 176
izolate Avatar answered Sep 20 '22 18:09

izolate