开发者

How can I make my site in the center of the page

开发者 https://www.devze.com 2023-01-15 01:32 出处:网络
I made a CSS template And I want to make it in the center of the page when I op开发者_开发百科en the browser

I made a CSS template

And I want to make it in the center of the page when I op开发者_开发百科en the browser it appears on the left of the page any help please


You need to use margin:auto with specified width like this:

#wrapper{
  margin:auto;
  width:1000px;  /* adjust width */
}

Where #wrapper is supposed to be the main container element on your page.


To get this centered properly, the wrapper needs to have a set width and we need to set the left and right margins to auto.

#wrapper {
width: 960px; /* set to width of content */
margin: 0 auto;
}

Sarfraz was on the right page, but there is no reason to set the top and bottom margins to auto. We should only affect the properties that are necessary to get the result we want.


user

body{
  margin:0 auto;
}
or top root parent id

#parentid{
margin:0 auto;
}


My method is slightly different to those already here so here's my suggestion.

div#wrapper {
    width: 960px;
    position: absolute;
    left: 50%;
    margin-left: -480px;
}

Where #wrapper is a div containing the main content of your site.

margin-left should equal whatever half of your width is.


Specify left and right margins as auto and set a width for the body:

body {
    margin-left: auto;
    margin-right: auto;
    width: 780px;
}

I chose 780px for the width, but you could put whatever you want. Specifying in other units (e.g. em, %) should work too.

0

精彩评论

暂无评论...
验证码 换一张
取 消