| | |
center the page? help
Please support our HTML and CSS advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
These are the 'bare' essentials of the CSS centering hack: the width and the margin. If you don't specify a width, the margin trick won't work. If you don't specify the left and right margins as
You may say: "But I specified a width: 100%!" --- good for you and in truth, your wrapper IS being centered correctly. However, the contents of the wrapper (such as your navigation or content divs) are still aligned to the left since that is the default behavior for elements inside a block.
You can see this behavior by adding
Now to fix your problem, you have to specify a width, preferably something slightly greater than the size (or percentage) of the content you put in your wrapper.
Try changing your .wrapper attributes to this:
Actually, you should start weaning yourself away from absolute positioning (there are exceptions) but your design can be implemented better without it... BAH alright, I'll still fix that search_bar.
Try this:
auto the wrapper won't be centered.You may say: "But I specified a width: 100%!" --- good for you and in truth, your wrapper IS being centered correctly. However, the contents of the wrapper (such as your navigation or content divs) are still aligned to the left since that is the default behavior for elements inside a block.
You can see this behavior by adding
border: 1px solid #F00 to your .wrapper div.Now to fix your problem, you have to specify a width, preferably something slightly greater than the size (or percentage) of the content you put in your wrapper.
Try changing your .wrapper attributes to this:
HTML and CSS Syntax (Toggle Plain Text)
.wrapper{ margin: 0 auto; width:1015px; }
Actually, you should start weaning yourself away from absolute positioning (there are exceptions) but your design can be implemented better without it... BAH alright, I'll still fix that search_bar.
Try this:
HTML and CSS Syntax (Toggle Plain Text)
.search_bar{ float: right; margin: 50px 80px 0 0; }
Last edited by kanaku; Dec 31st, 2008 at 1:21 am. Reason: added a little extra width (in case the elements have padding)
If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
When I check your site, the page still isn't centered. Why is that?
It's size
It's size
div.wrapper is still 100%. Tell me when you've updated your site so I can see how to fix the search bar. If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
>.< Crusty logo image is taking up the whole top portion of your nav div. Set the attributes of your .logo class to this:
Then change your search_bar class to this:
You can tweak the margins to fit your layout... I can't estimate how much margin you want.
HTML and CSS Syntax (Toggle Plain Text)
.logo{ border-style:none; float: left; }
Then change your search_bar class to this:
HTML and CSS Syntax (Toggle Plain Text)
.search_bar{ display: block; float: right; margin: 30px 2px 0 0; }
You can tweak the margins to fit your layout... I can't estimate how much margin you want.
Last edited by kanaku; Dec 31st, 2008 at 4:41 pm. Reason: made the code 'purtier'
If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
•
•
•
•
and what mite you suggest i use instead of absolute positioning?
display attribute.
If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Visit this thread if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
![]() |
Similar Threads
- Align floated images in center of page with CSS (HTML and CSS)
- Why does text wrap around from middle of page? (Windows Software)
- Table in center of page? (HTML and CSS)
Other Threads in the HTML and CSS Forum
- Previous Thread: Need Help!!! Internet Explore not reading my webpage...
- Next Thread: Need Help in HTML
Views: 1174 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for HTML and CSS
2002 appointments asp background backgroundcolor beta browser bug calendar cart center cgi code codeinjection corporateidentity create css deleted design development displayimageinsteadofflash dreamweaver drupal emailmarketing epilepsy explorer firefox flash font fonts form format free frontpage google griefers hackers hitcounter hover html ide ie7 ie8 iframe image images internet internetexplorer intranet iphone javascript jpeg layout macbook maps marketshare microsoft missing mozilla multimedia navigationbars news offshoreoutsourcingcompany opacity opera optimization perl pnginie6 positioning problem scroll seo shopping studio swf swf. templates textcolor theme timecolor titletags url urlseparatedwords visual visualization web webdevelopment webform website windows7 wordpress xml xsl





