Created
May 12, 2016 11:56
-
-
Save peccu/37b10b40c45e2f946e1aeff034c006c2 to your computer and use it in GitHub Desktop.
Floating box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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