Skip to content

Instantly share code, notes, and snippets.

@peccu
Created May 12, 2016 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peccu/37b10b40c45e2f946e1aeff034c006c2 to your computer and use it in GitHub Desktop.
Save peccu/37b10b40c45e2f946e1aeff034c006c2 to your computer and use it in GitHub Desktop.
Floating box
<div style='height: 600px'></div>
test
<div style='height: 600px'></div>
test
<div class='box' id='box'>
<div id='content'>
centered content<br>
centered content<br>
centered content<br>
centered content
</div>
</div>
var marginWidth = 50;
var h = document.getElementById('content').offsetHeight;
document.getElementById('box').style.height = (h + marginWidth) + 'px';
var marginHeight = 80;
var w = document.getElementById('content').offsetWidth;
document.getElementById('box').style.width = (w + marginHeight) + 'px';
.box{
color: white;
background-color: #a9a9a9;
/* centering in window */
margin: auto;
/* centering in page */
justify-content: center;
/* abusolute position */
position: fixed;
/* set origin to center */
top: 0;
right: 0;
bottom: 0;
left: 0;
/* for contents in .box*/
display: flex;
/* vertical center */
align-items: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment