I have an element whose width I'd like to animate when its contents change. It has width: auto
, and this never changes. I've seen this trick, but that's for transitioning between two values and one is set. I'm not manipulating the values at all, only the content, and I'd like my element's size to change with animation. Is this at all possible in CSS?
Here's a simplified version of my code:
.myspan {
background-color: #ddd;
}
.myspan:hover::after {
content: "\00a0\f12a";
font-family: Ionicons;
font-size: 80%;
}
<link href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet"/>
<html>
<body>
<span class="myspan">Hello!</span>
</body>
</html>
I'd like the changing size to animate when the user hovers over the element.
auto
with CSS only. Either use the "max-height" trick you've linked to or, on page load, run a small script which sets the final height – Eldamax-width
trick you give it a value that is big enough to accommodate the widest. If you post your HTML and CSS I might be able to make a sample for you – Eldaelem:hover::after
) – Extremely