Tuesday, July 28, 2015

to center a DIV on the screen

<style>
.center {
  position: absolute;
  width: 64px;
  height: 64px;
  left: calc(50% - 64px/2); /* width divided by 2*/
  top: calc(50% - 64px/2); /* height divided by 2*/
}
</style>

Note: calc() allows you to do basic calculations in css.

Reference:

http://stackoverflow.com/questions/210717/using-jquery-to-center-a-div-on-the-screen

No comments: