Jump to content

Vertically centering a Div in any screen resolution


departedmind

Recommended Posts

Hello,

Is there any way to vertically center a DIV within a browser window in any screen resolution?

 

I tried by keeping a main container DIV to 100% height and width, made its position fixed and kept child container inside it (saw an example while searching in google), It seems to work but the problem is when i resize my browser scrollbar does not seem to show.

 

Any solution....

<div id="expand">
  <div class="middle"><div class="inner">
      Contents!
  </div></div>
</div>

 

* Modern Browsers, not IE7 */

html>/**/body #expand {
position:fixed;
top:0;
left:0;
width: 100%;
height: 100%;
}
html>/**/body #expand .middle {
display:table;
margin: 0 auto;
height: 100%;
}
html>/**/body #expand .inner {
vertical-align:middle;
display:table-cell;
}

/* Only IE7 */
*:first-child+html #expand {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
*:first-child+html #expand .middle {
position:absolute;
top:50%;
left: 50%;
}
*:first-child+html #expand .inner {
position:relative;
top:-50%;
left:-50%;
}
*:first-child+html #expand .main {
margin: -3px 0 0 0;
}

 

Css hacks are necessary for IE7. Conditional stylesheets will not work as a subsitute. I have tried it before, but for some reason IE7 conditional stylesheets trigger an unkown bug that causes height: auto; to be inherited, thus creating issues.  :-\

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.