Okay, I want to position overlapping elements based on the order they appear in a list. So the first will not be translated, the second will be translated 60px, the third 120px, etc... This is just a simplified version of what I achieve. Also, in the example there are three elements, in real life I won't know how many elements there will be. This is variable.
Below is a simple snippet that can achieve what I want, but you can easily see the problem with this: way to many lines of css... So the question is, how to position something based on its order? I assume that I should do something with :nth-child(n)
? But how can I use the order of the element (n) to calculate its position?
.wizard :nth-child(1) {
position: absolute;
width: 400px;
border-style: solid;
transform: translateX(calc(0 * 60px));
}
.wizard :nth-child(2) {
position: absolute;
width: 400px;
border-style: solid;
transform: translateX(calc(1 * 60px));
}
.wizard :nth-child(3) {
position: absolute;
width: 400px;
border-style: solid;
transform: translateX(calc(2 * 60px));
}
<div class="wizard">
<div class="step" style="background-color: red;">Step 1</div>
<div class="step" style="background-color: yellow;">Step 2</div>
<div class="step" style="background-color: green;">Step 3</div>
</div>
UPDATE: This is what I really want (in the end), where the different steps are sliding in from right to left...