This question is out of curiosity, to explore the limits of CSS and get a better understand of the layout possibilities. Consider the following example:
.container {
display: inline-block;
width: 6rem;
vertical-align: -4rem;
}
.item {
width: 6rem;
height: 2rem;
background-color: lightblue;
line-height: 2rem;
}
.item.active {
color: white;
background-color: darkblue;
}
The selected element:
<div class="container">
<div class="item a">Pineapple</div>
<div class="item b active">Apple</div>
<div class="item c">Tomato</div>
<div class="item d">Banana</div>
</div>
Is it possible, with pure CSS, to always keep the active item aligned with the description text without hardcoding the number of items? In the example, you can see that the second item is active, and the description text is aligned to it.
My ideas:
- Is there some way to only make elements before the active element contribute to the height of the box? Then
vertical-align: bottomshould do what I want. However, I haven't found a way to do that while keeping the stacking of items intact. - Floats don't always contribute to the height of a container, but
inline-blockensures that all floats are contained. Perhaps there is a way to achieve this with floats and a few more levels of containers?