What I want to achieve is something like this:
.parent {
min-width: 64px;
width: auto;
height: 64px;
background-color: purple;
display: inline-block;
}
.child {
width: 24px;
height: 24px;
background-color: yellow;
transition: all 0.5s ease;
}
.child:hover {
width: 256px;
}
<div class="wrapper">
<div class="parent">
<div class="child"></div>
</div>
</div>
<div class="wrapper">
<div class="parent">
<div class="child"></div>
</div>
</div>
<div class="wrapper">
<div class="parent">
<div class="child"></div>
</div>
</div>
The key that I was able to make the parents grow as their children grow is by using display: inline-block
for the parent, but to make them align vertically I have to use an extra wrapper for each parent, or placing a <br>
after each parent like this:
<div class="parent">
<div class="child"></div>
</div><br>
<div class="parent">
<div class="child"></div>
</div><br>
<div class="parent">
<div class="child"></div>
</div><br>
But in doing so there is always a tiny gap that I couldn't remove between the parents. Is there a way to remove the wrapper to make the structure simpler like this to work (to have the same effect as the first example):
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>
<div class="parent">
<div class="child"></div>
</div>