I'm currently working on a component that involves circles and lines, and I'm trying to gain a better understanding of how flexbox works its magic. Specifically, I want to dive deeper into the flex property.
Visually, all three versions have the same number of items, but the first one appears normal while the other two do not scale correctly.
What is causing this issue?
How can it be resolved?
.chart {
display: flex;
flex-direction: row;
align-items: center;
padding: 0 15px;
margin-bottom: 50px;
}
.dot-black {
width: 8px;
height: 8px;
border-radius: 4px;
background: black;
}
.dot-grey {
width: 22px;
height: 22px;
border-radius: 11px;
background: grey;
}
.dot-green {
width: 22px;
height: 22px;
border-radius: 11px;
background: green;
}
.line-black {
height: 2px;
background: black;
flex: 1;
}
.line-grey {
height: 2px;
background: grey;
flex: 1;
}
.gradient {
display: flex;
opacity: 0.2;
flex: 6;
align-items: center;
}
<div class="chart">
<div class="gradient" style="flex: 1">
<span class="dot-black"></span>
<span class="line-black"></span>
<span class="dot-grey"></span>
</div>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
</div>
<div class="chart">
<div class="gradient" style="flex: 1">
<span class="dot-black"></span>
<span class="line-black"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
</div>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
</div>
<div class="chart">
<div class="gradient" style="flex: 2">
<span class="dot-black"></span>
<span class="line-black"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
</div>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
<span class="line-grey"></span>
<span class="dot-grey"></span>
</div>