View Full Version : How to centre align a Div
neilkw
03-29-2006, 09:17 AM
Just learning the div tag and all I need to do is centre align it. Played around with left and right position but I'm a beginner and all i need is to center align it!
Show me how silly I'm being, pease.
Thanks.
here's my div
<div id=layer1 style="position:absolute; top:20; left:30%; width:300px; height:321px; z-index:1; padding:5px; border: #000000 2px solid; background-color:#6666ff;">
Content goes here (images, text) </div>
souravsaha86
03-29-2006, 09:37 AM
i think u wanted to put the text stuffs in centre. did i get u? if so then for that the stuff i gess is quite simple.
just put
<center>
.........
..........watever u want in center here...........
.........
</center>
and it should come in centre. was that tough? lollllllllllllll
neilkw
03-29-2006, 09:42 AM
Hi and thanks for your reply. I do seem to have grasped alignment of text within the div but I want to have my actual div layer centre aligned. I need it to move when the page is resized, so that it remains in the middle whatever the screen size is.
neilkw
03-29-2006, 01:33 PM
This seems to have solved my problem
http://www.bluerobot.com/web/css/center1.html
djr33
03-30-2006, 05:57 AM
Misconception: <center>...</center> tags.... it's not really unique... but rather a shortcut for:
<div align="center">...</div>
If you want the actual layer to be alinged, you'll have to do more than that, 'cause that affects inside. You could do:
<div align="center">
<div>
(this div is centered)
</div>
</div>
Depends. You said you solved it. Hopefully this'll make it make more sense :)
neilkw
03-30-2006, 08:49 AM
cheers for your reply.
I have achieved my desired placement by assigning the placement attributes via the style sheet. float left/right etc. Then assigning the div into the css.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.