tags:

views:

47

answers:

4

like:

<body>
<div></div>
<div></div>
</body>

How can I make all the DIVs at the center of the webpage?

I mean in the browser.

+2  A: 

HTML:

<div class="center"></div>

CSS:

div.center { margin: 0 auto; }

Of course, if you have other things outside of those divs, they might interfere.

kijin
not working, please verify.
Bin Chen
the divs need to have a specific width set for this to work, e.g. `div.center { margin: 0 auto; width: 800px }`
Graham Clark
I conditionally accepts this answer, the Graham Clark has a more accurate complement comment.
Bin Chen
@Graham Clark thanks for the clarification.
kijin
+1  A: 

Either create a CSS class or put in a style in your DIV element

margin:0px auto;

arame3333
`px` is redundant, because any unit multiplied by zero is zero anyway.
kijin
+1  A: 

Depends on the exact page, but either text-align: center or margin: 0 auto will probably be what you need. See CSS Centering for general information about centering and CSS Selectors so you know how to target the proper elements.

Yevgeniy Brikman
If you use text-align: center; ensure you then use text-align: left; on the content within the divs, otherwise everything will be centred.
Lazlow
Yup, it says exactly that in the CSS Centering link I posted.
Yevgeniy Brikman