Skip to content

Instantly share code, notes, and snippets.

@LeaVerou
Created December 1, 2012 17:51
Show Gist options
  • Save LeaVerou/4183564 to your computer and use it in GitHub Desktop.
Save LeaVerou/4183564 to your computer and use it in GitHub Desktop.
Transition to height:auto on replaced elements
/**
* Transition to height:auto on replaced elements
* CSS brain teaser: If transitions to/from height:auto don’t work, why is the height transitioning here?
And why is it not transitioning when it shrinks but only when it grows?
Scroll down for the solution.
*/
img {
width: 0; height: 0;
transition: 1s linear;
}
html:hover img {
width: 200px; height: auto;
}
/*
Solution:
Non-animatable value changes happen immediately. So, on mouse over, height:auto is applied immediately and then
because the width is animated, the height animates as well, because the image has an intrinsic aspect ratio.
On mouse out, height:0 is applied immediately as well, so we don't see any transition for the width.
*/
<p>Hover over here</p>
<img src="http://placekitten.com/400/300" />
// alert('Hello world!');
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"css"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment