How to make my site in the center of the page

I created a CSS template.
And I want to do this in the center of the page. When I open the browser, it appears to the left of the page. Any help please.

+3
source share
5 answers

You need to use margin:autowith the widthfollowing as follows:

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

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

+12
source

To get this right, the wrapper must have a given width, and we must set the left and right margins automatically.

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

Sarfraz , auto. , .

+2

user

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

#parentid{
margin:0 auto;
}
0
source

My method is slightly different from those already here, so here is 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 any half of your width.

0
source

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

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

I chose 780px for the width, but you could fit whatever you want. A job in other units (e.g. em,%) should also work.

0
source

Source: https://habr.com/ru/post/1762850/


All Articles