Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering a div to the middle of the web page?

I want to make my div be positioned in the middle-center part of the web page. I'm attempting to make a pre-loader div which should be in the middle-center part of the web page and after the page loads, that div will be hidden. How can I achieve such?

The div should be centered horizontally and vertically.

like image 679
Registered User Avatar asked Dec 07 '22 23:12

Registered User


2 Answers

<div class = 'middle'></div>

.middle{
  margin: auto;
  width: 900px;
}
like image 142
Spyros Avatar answered Dec 23 '22 17:12

Spyros


to center a div both hor and ver you could do this way:

markup

<div class="centered"></div>

css

.centered{
    position:absolute;
    width:100px;
    height:100px;
    left:50%;
    top:50%;
    margin-left:-50px;
    margin-top:-50px;
}

fiddle: http://jsfiddle.net/steweb/qSvAQ/1/

like image 31
stecb Avatar answered Dec 23 '22 18:12

stecb