Jump to content

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.  :-\

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.