I am looking for a CSS solution on applying a background color to a vertical timeline axis on the previous event from the current
.timeline {
position: relative;
display: flex;
margin: 10px;
flex-direction: column;
}
.timeline .event {
position: relative;
display: flex;
flex-direction: row;
padding-left: 15px;
}
.timeline .event::before {
content: '';
position: absolute;
top: 0px;
left: 2px;
bottom: 0px;
width: 2px;
background: #d9d9d9;
}
.timeline.descending .event.open + .event:nth-child(3n-1)::before {
background: #555555;
}
<div class="timeline descending">
<div class="event">
Event 1
</div>
<div class="event">
Event 2
</div>
<div class="event open">
Event 3
</div>
<div class="event">
Event 4
</div>
<div class="event">
Event 5
</div>
<div class="event">
Event 6
</div>
</div>
In the above example, I have class open for Event 3
, I am trying to change the color of Event 2
axis with #555555
, I wrote code like -
.timeline.descending .event.open + .event:nth-child(3n-1)::before {
background: #555555;
}
Which didn't work!
But, when I modified the code to
.timeline.descending .event + .event:nth-child(3n-1)::before {
background: #555555;
}
.timeline {
position: relative;
display: flex;
margin: 10px;
flex-direction: column;
}
.timeline .event {
position: relative;
display: flex;
flex-direction: row;
padding-left: 15px;
}
.timeline .event::before {
content: '';
position: absolute;
top: 0px;
left: 2px;
bottom: 0px;
width: 2px;
background: #d9d9d9;
}
/* .timeline .event:nth-child(1)::before {
background: #000000;
} */
.timeline.descending .event + .event:nth-child(3n-1)::before {
background: #555555;
}
<div class="timeline descending">
<div class="event">
Event 1
</div>
<div class="event">
Event 2
</div>
<div class="event open">
Event 3
</div>
<div class="event">
Event 4
</div>
<div class="event">
Event 5
</div>
<div class="event">
Event 6
</div>
</div>
I am able to run it, and it gives me partial result. I have limited understanding of nth-child
and nth-last-child
working, any help here would be appreciated.