different style for continuous css class
For a vanilla CSS solution, you can use a pseudo element to do this for you:
set
border-radius: 25px
to thebg
element,fill the border gaps in successive
bg
elements using a pseudo element that is positioned absolutely and stacked behind thebg
elements, and shifted using a negative margin.
See demo below:
.row {
display: flex;
margin: 20px;
}
.number {
width: 32px;
height: 32px;
display: flex;
justify-content: center;
align-items: center;
}
.number.bg {
background-color: #e24381;
color: #ffffff;
border-radius: 25px;
position: relative;
}
.number.bg+.bg:before {
content: '';
display: block;
background-color: #e24381;
margin-left: -50%;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
position: absolute;
}
<div class="row">
<div class="number">1</div>
<div class="number bg">2</div>
<div class="number bg">3</div>
<div class="number bg">4</div>
<div class="number">5</div>
<div class="number">6</div>
<div class="number bg">7</div>
</div>
Here is an idea using some pseudo element and without JS:
.row {
display: flex;
margin: 20px;
position:relative;
z-index:0;
}
.number {
width: 32px;
height: 32px;
display: flex;
justify-content: center;
align-items: center;
}
.number.bg {
background-color: #e24381;
color: #ffffff;
border-radius: 24px;
position:relative;
}
.bg +.bg:before {
content:"";
position:absolute;
z-index:-1;
background:inherit;
top:0;
bottom:0;
left:-50%;
right:50%;
}
body {
background:pink;
}
<div class="row">
<div class="number">1</div>
<div class="number bg">2</div>
<div class="number bg">3</div>
<div class="number bg">4</div>
<div class="number">5</div>
<div class="number">6</div>
<div class="number bg">7</div>
</div>