-6

How do I center a div at the middle of my page in html using CSS?

Something like www.google.com, when you go to the site, you will see the search bar and the logo are centered in the middle of the page.

Any way to go around this?

Chris Otaalo
  • 131
  • 2
  • 10

4 Answers4

0

MARKUP

<div class="outer"><div class="inner">your content</div></div>

STYLE

.outer {
  display: table-cell;
  width: 500px;
  height: 500px;
  vertical-align: middle;
  text-align: center;
}

.inner {
  display: inline-block;
  width: 200px;
  height: 200px;
  text-align: left;
}

DEMO

Benjamin
  • 2,612
  • 2
  • 20
  • 32
0

center the div using margin : auto.

Html:

<div id="center"></div>

And css:

#center {
    margin : auto;
    display : inline-block;
}
julienc
  • 19,087
  • 17
  • 82
  • 82
Rahiil
  • 110
  • 1
  • 11
0
<div class = "center_me">Some content</div>

corresponding CSS to center the div would be,

.center_me {
 dislay: table;
 margin: 0px auto;
 }

or,

.center_me {
 display: table;
 width: 50%;
}
Thomas Sebastian
  • 1,582
  • 5
  • 18
  • 38
-1

Try this;

Html:

<div id="element">your element</div>

css

#element {
  width: 200px;
  display: block;
  margin: 0 auto;
}
eman.lodovice
  • 192
  • 1
  • 6