[英]How to apply different border-color for each slick slider item
I need to apply different border-color for each slick slider item with 5 colors staring with red, i tried the code below it does not work, it applies only the first color to all items when I apply slick-slider to it.我需要为每个光滑的 slider 项目应用不同的边框颜色,其中 5 个 colors 以红色凝视,我尝试了下面的代码它不起作用,当我对其应用光滑滑块时,它仅将第一种颜色应用于所有项目。
<div class="slider">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
.slider {
display: flex;
gap: 20px;
flex-direction: row;
}
.slider > div {
height: 50px;
width: 50px;
background-color: blue;
}
.slider > div:nth-child(5n+1) {
border: 5px solid red;
}
.slider > div:nth-child(5n+2) {
border: 5px solid orange;
}
.slider > div:nth-child(5n+3) {
border: 5px solid yellow;
}
.slider > div:nth-child(5n+4) {
border: 5px solid pink;
}
.slider > div:nth-child(5n+5) {
border: 5px solid green;
}
Use css variables使用 css 个变量
<div class="slider">
<div style='--clr:#000'></div>
<div style='--clr:#fff'></div>
------
</div>
.slick-item{
border:5px solid var(--clr);
}
You just need to alter the nth-child settings:您只需要更改第 nth-child 设置:
.slider { display: flex; gap: 20px; flex-direction: row; }.slider>div { height: 50px; width: 50px; background-color: blue; }.slider>div:nth-child(5n+1) { border: 5px solid red; }.slider>div:nth-child(5n+2) { border: 5px solid orange; }.slider>div:nth-child(5n+3) { border: 5px solid yellow; }.slider>div:nth-child(5n+4) { border: 5px solid pink; }.slider>div:nth-child(5n+5) { border: 5px solid green; }
<div class="slider"> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.