Search code examples
cssheightcentervertical-alignment

Vertically center a div based on browser screen


is it possible to center a div vertically based on the browser screen height?

I have this

#success {
  height: 300px;
  top: 50%;
  margin-top: -150px;
  position: absolute;
}

but this centers vertically to it's parent div, and not based on the browser screen height. Is there a way where I can achieve what I want? Thanks!


Solution

  • Give the div position: fixed and it will be positioned relative to the window.