Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Old 11-04-2006, 01:00 AM Center elements
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
Trades: 0
How do you center block elements,
Code:
margin-left:auto and margin-right:auto
should work but it doesnt.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
lunchbox170 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-04-2006, 02:41 AM Re: Center elements
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
You need to specify a width, otherwise it will just assume full width:
Code:
<div style="margin:  0px auto;  width:  760px;  text-align:  center;">
...
</div>
The text-align: center is for IE 5.5 and earlier. Make sure you counter that in your nested block elements with a text-align: left.

You'll also notice the syntax I used. When two values are put after margin: , the first value applies to top/bottom and the second to left/right.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 11-05-2006, 12:43 AM Re: Center elements
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
Trades: 0
that didnt work, i made the width 100% because I want it the be centered for the whole page.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 11-05-2006, 02:17 AM Re: Center elements
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
That's precisely WHY it won't work. margin: 0px auto; will only fill in the remaining left and right margins AFTER the width of the div has been calculated.

If your div width is 100%, then there's no more margin to fill on either side since your div is filling up the whole page anyway.

In other words, you need to specify a div width that isn't 100%. The syntax does work and work well (see these sites for two working examples: http://www.lightenupontario.ca and http://www.greenbuildingfest.com ). If you want your div to span the width of the page AND be centered...that's simply not going to work.

In other words, you need to rethink your math.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 11-05-2006, 07:58 PM Re: Center elements
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
Trades: 0
Ok, I didnt understand what exactly margin: 0px auto; did at first but now I get it, that makes sense.

Thanks
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 11-06-2006, 03:04 PM Re: Center elements
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
No probs, dude. Good luck to you!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to Center elements
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.47644 seconds with 12 queries