Center Box with CSS

Q

Quijote

Hello

I've this CSS code:

....
#content {
padding: 10px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: auto;
margin-left: auto;
background-color: #333333;
....

that center orizzontally the content box but if I need to center vertically
too how can I do?

Thanks so much !!
 
W

Whitecrest

quijote14 said:
that center orizzontally the content box but if I need to center vertically
too how can I do?

<div style="position:absolute;height:100%;width:100%">
<div style="position:absolute;top:50%;left:50%">Hey</div>
</div>

This will open the word "hey" (or the contents of that div) in the
center of the browser window. You can take the needed pieces and use it
in your css.
 
G

Gnarlodious

Entity Quijote spoke thus:
Hello

I've this CSS code:

...
#content {
padding: 10px;
margin-top: 10px;
margin-bottom: 10px;
margin-right: auto;
margin-left: auto;
background-color: #333333;
...

that center orizzontally the content box but if I need to center vertically
too how can I do?
Ah, the eternal vertical centering problem!
There's a good analysis and solution here:
<http://www.hicksdesign.co.uk/articles/css/vertical_centering_with_css>

-- Gnarlie
Currently broadcasting from http://68.165.192.233
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top