Skip to content

Instantly share code, notes, and snippets.

@mistakster
Created March 29, 2013 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save mistakster/5269143 to your computer and use it in GitHub Desktop.
Save mistakster/5269143 to your computer and use it in GitHub Desktop.
Align vertically absolutely positioned element without known height
/**
* Align vertically absolutely positioned element without known height
*/
#has-known-height {
background: lightgray;
height: 300px;
}
#absolutely-positioned {
position: absolute; /* don't touch this property */
background: blue;
color: white;
}
<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>
// alert('Hello world!');
{"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