Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - center everything within the body tag

I am trying to center everything within the tag on the page without adding another container within it. My situation doesn't allow me to change the markup that is being generated but I am able to edit the CSS. My overall objective is to create css that allows me to use the zoom tag in IE for the print css (to zoom out), but the way it is currently working, this creates a lot of white space on the right side and I'd like to make sure the content is always centered in the middle.

like image 596
Ben Avatar asked Jun 23 '10 16:06

Ben


People also ask

How do I center everything in my body CSS?

You do this by setting the display property to “flex.” Then, define the align-items and justify-content property to “center.” This will tell the browser to center the flex item (the div within the div) vertically and horizontally.

How do I center a tag in CSS?

Use the text-align: center; on a parent element to center align all the child elements inside it.

How do I center a body tag in HTML?

HTML | <tbody> align Attribute left: It sets the text left-align. right: It sets the text right-align. center: It sets the text center-align. By default, it is set to center.


1 Answers

If you're ok with giving the body a fixed width, you can center it by giving it a width and a margin of auto for the left and right margins:

E.g:

body { width: 960px; margin: 0 auto; }
like image 146
jimr Avatar answered Oct 16 '22 09:10

jimr