-
-
Save iamstarkov/5269246 to your computer and use it in GitHub Desktop.
Align vertically absolutely positioned element without known height
This file contains hidden or 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
/** | |
* Align vertically absolutely positioned element without known height | |
*/ | |
#has-known-height { | |
position: relative; | |
background: lightgray; | |
height: 300px; | |
} | |
#absolutely-positioned { | |
position: absolute; /* don't touch this property */ | |
background: blue; | |
color: white; | |
top: 0; | |
bottom: 0; | |
margin-top: auto; | |
margin-bottom: auto; | |
} |
This file contains hidden or 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 id="has-known-height"> | |
<div id="absolutely-positioned"> | |
Align me vertically, please.<br> | |
You can add as many elements and styles as you need,<br> | |
but <strong>#absolutely-positioned</strong> should have | |
<code>position: absolute;</code> | |
</div> | |
</div> |
This file contains hidden or 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
// alert('Hello world!'); |
This file contains hidden or 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
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"all"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment