![]() |
Centering DIV to resolution
Hey guys, I need to fix this problem ASAP. It's for a client.
I have a design that is about 800pixels. Im trying to center it to all resolutions in css. My "wrapper" is in the body: <body id="wrapper"> and basically its suppose to wrap the entire body into a position where it will look centered, but its not. Here is the code: Code:
#wrapper { |
First, make a div like: <div id="wrapper">.
Then apply the following css: Code:
body { text-align: center; } |
im looking for the entire DIV to be centered not just the text. The text where its at, its suppose to be there.
|
Code:
#wrapper { margin: 0 auto;width: 80% }The body { text-align: center } is only necessary if you want this to work in IE6. |
Quote:
And indeed, you have to set a width on the wrapper. |
#wrapper { margin: 0 auto; width:800px; }
will work in all browsers. You dont need a text align center in the body tag. I have never done that and it always works in all browsers. |
cory it worked but what I'm noticing is that its not wrapping around the other DIVs. Is it because i made them absolute?
thanks! |
If want #wrapper to wrap around absolute div you got to add position: relative;
to #wrapper. |
hm i did and it didnt do anything :/
|
Ye the absolute will position that tag in the exact location you place it no matter what. In general you should use relative, , which I believe is the default if you don't set one, and try to avoid absolute. However I say thay and sometimes it is much easier to use absolute positioning, but I wouldn't use it on a lot of different elements, It will lead to future problems. Try removing all of the absolute positioning and then going from there and see what happens.
|
If you all still are wondering how to do this, this is the most logic, easy and compatible way to all resolutions, browsers and OS's.
HTML code Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">Code:
@charset "utf-8"; |
You really want to avoid the
* { width: 100%; height: 100%; margin: 0px; padding: 0px; } Thats terrible programming. It says you want to apply that to every single tag on the page. Why would you want every tag to be like that? The easiest way to do this is simply this HTML Quote:
CSS Quote:
|
I admit that the width and so forth are totally not necessary and could completely mess up the page. As for the font-size, color and of course padding and margin, that's just general knowledge. You don't want auto-padding, you want to correct and adjust it manually.
The charset is simply the type of encoding used. ;-) |
| All times are GMT. The time now is 09:55 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0