Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute Positioning & Text Alignment

Tags:

html

css

I would like some text to be centered in the bottom of the screen.

I tried this, but it doesn't work. It looks like absolute positioning conflicts with the alignment.

How could I achieve this simple task ?

like image 631
Misha Moroshko Avatar asked May 11 '10 06:05

Misha Moroshko


2 Answers

The div doesn't take up all the available horizontal space when absolutely positioned. Explicitly setting the width to 100% will solve the problem:

HTML

<div id="my-div">I want to be centered</div>​ 

CSS

#my-div {    position: absolute;    bottom: 15px;    text-align: center;    width: 100%; } 

like image 146
Pär Wieslander Avatar answered Oct 22 '22 10:10

Pär Wieslander


Try this:

http://jsfiddle.net/HRz6X/2/

You need to add left: 0 and right: 0 (not supported by IE6). Or specify a width

like image 37
Eric Avatar answered Oct 22 '22 09:10

Eric