marius
marius

Reputation: 1266

CSS - Div object centering?

I'd simply like to center a DIV object to the browser screen.

It should be something like that I think..

<div id="root">
    <div id="centeredElement"></div>
</div>

div#root {
    width:100%; 
}
div#centeredElement {
    width:500px;
    height:200px;
    align:center;
}

Upvotes: 3

Views: 26914

Answers (3)

T.Todua
T.Todua

Reputation: 56487

you have several options to center a div, image or other object:

1) everything inside div

<div align="center"> blabla </div>

2) for images or frames

<img style="display:block;margin-left:auto;margin-right:auto;" align="center" src="xx.jpg" />

3) another:

<div style="width:80%;margin-left:10%;"> blabla </div>

Upvotes: 2

Rohit Azad Malik
Rohit Azad Malik

Reputation: 32192


text-align:center or margin:0 auto;

as like this

div#centeredElement{
text-align:center;
}

or

div#centeredElement{
margin:0 auto;
}

Upvotes: 3

ragklaat
ragklaat

Reputation: 946

Change

align:center

to

margin: 0px auto;

Upvotes: 1

Related Questions