I have a number of fixed-size items in a container of limited size. If there are too many child items, I would like them to start overlapping (right right most on top), rather than overflowing or wrapping.
Can this be done by just styling the the container and child elements themselves, without JavaScript or special elements?
<div class="items">
<div>A</div>
<div>B</div>
</div>
The desired effect is this, but without the extra wrapper divs
and having to know the base item width ahead of time (the width on .items > div
).
.items {
background: #FFB600;
display: flex;
flex-direction: row;
left: 5px;
bottom: 5px;
width: 90px;
padding: 8px;
margin: 10px;
}
.items > div {
flex: 0 1 20px;/*16px icon + 4px spacing*/
height: 16px;
position: relative;
}
.items > div > div {
position: absolute;
width: 16px;
height: 16px;
opacity: 0.9;
}
/*Give each a different colour / apperance*/
.items > div:nth-child(1) > div {
background: #0026FF;
}
.items > div:nth-child(2) > div {
background: #0094FF;
}
.items > div:nth-child(3) > div {
background: #004A7F;
}
.items > div:nth-child(4) > div {
background: #00137F;
}
.items > div:nth-child(5) > div {
background: #7F92FF;
}
.items > div:nth-child(6) > div {
background: #7FC9FF;
}
.items > div:nth-child(7) > div {
background: #007F7F;
}
.items > div:nth-child(8) > div {
background: #00FFFF;
}
<div class="items">
<div>
<div></div>
</div>
</div>
<div class="items"><div><div></div></div><div><div></div></div></div>
<div class="items"><div><div></div></div><div><div></div></div><div><div></div></div></div>
<div class="items"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div>
<div class="items"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div>
<div class="items"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div>
<div class="items"><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div><div><div></div></div></div>