Monday, February 1, 2016

quick hack to center horizontally AND vertically on page...

I participated in my 8th Global Game Jam. I wasn't as delighted in my team's game (Dinner Party Faux Pas) as much as I have been previous years, but it was a fun exercise in making a game directly in the DOM (instead of the canvas) and I learned one decent trick: to center a div (or whatever) horizontally AND vertically, you can CSS something like the following:
  width:400px;  
  height:400px;
  background-color:red;
  margin:auto;
  position:absolute;
  top:0;
  bottom:0;
  left:0;
  right:0;
Pretty nifty.

No comments:

Post a Comment