Use a pseudo element for the background:
.skill-container .skill {
color: white;
background-color: lightgray;
margin: 5px 0;
padding: 10px 0 10px 4px;
overflow: hidden;
border-radius: 5px;
white-space: nowrap;
position: relative;
z-index:0;
}
.skill-container .skill::before {
content: "";
position: absolute;
background-color: #312E81;
border-radius: inherit;
z-index: -1;
top: 0;
bottom: 0;
left: 0;
animation: animateLeft 1s ease-out;
}
@keyframes animateLeft {
from {
transform: translateX(-100%);
}
}
.skill-container .skill.skill-level-70::before {
width: 70%
}
.skill-container .skill.skill-level-40::before {
width: 40%
}
.skill-container .skill.skill-level-100::before {
width: 100%
}
<div class="skill-container">
<div class="skill skill-level-100">CSS</div>
<div class="skill skill-level-70">HTML</div>
<div class="skill skill-level-40">PHP</div>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…