3 replies [Last post]
flashbang
Offline
newbie
Last seen: 16 years 27 weeks ago
Joined: 2003-05-30
Posts: 1
Points: 0

hi. i would like to know if any of you have found a way to center an element within another element, or just center an element in a page. For example, I have a logobar on top of my page, that is about 50% of the width of the page. I would like to center that without using relative positioning. I know the hack to make it work in IE
<div style="text-align: center;">

</div>
IE then centers the element between the div tags, because of the text-align.. But Mozilla and Phoenix/Firebird do not do this. Is there any attribute in CSS without using absolute positioning that we can use to center an element? something like a float: center;? This is really important ot me and i would appreciate any answers. Thanks a lot Smile

TGecho
Offline
Regular
Last seen: 16 years 31 weeks ago
Joined: 2003-05-06
Posts: 11
Points: 0

how to center an element w/ css layout

Anonymous
Anonymous's picture
Guru

how to center an element w/ css layout

Hi,

Make a div that will just contain your image and then put the image as the background imagve for the div. Then you can position it using the center center attributes.

HTH,

Jo

Anonymous
Anonymous's picture
Guru

how to center an element w/ css layout

Anonymous wrote:
Hi,

Make a div that will just contain your image and then put the image as the background imagve for the div. Then you can position it using the center center attributes.

HTH,

Jo

Oops! That's supposed to be "image". :roll:

It also might help if I give an example. Laughing out loud

div.topbar {background-image: url(topbar.jpg); background-repeat: no-repeat;}

Then, just call your <div class-"topbar"> where you want it on the page.