检查时如何更改单选按钮背景颜色
我有一个简单的幻灯片,带有3张图像,我需要制作检查按钮的背景颜色(显然,每个按钮是指一个IMG)。我实际上尝试了Google中所有可能的解决方案,如果有人能帮助我,我将非常感谢。提前致谢!
这是我的幻灯片代码:
.slider {
transform: translateX(20%);
display: inline-block;
position: relative;
width: 61%;
overflow: hidden;
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px 0px;
}
.images {
display: flex;
width: 100%;
}
.images img {
width: 100%;
transition: all 0.15s ease;
}
.images input {
display: none;
}
.dots {
display: flex;
justify-content: center;
margin: 5px;
}
.dots label {
height: 15px;
width: 15px;
border-radius: 50%;
border: solid #13447E 3px;
cursor: pointer;
transition: all 0.15s ease;
margin: 5px;
}
#img1:checked ~ .m1 {
margin-left: 0;
}
#img2:checked ~ .m2 {
margin-left: -100%;
}
#img3:checked ~ .m3 {
margin-left: -200%;
}
<div class="slider">
<div class="images">
<input type="radio" name="slide" id="img1" checked>
<input type="radio" name="slide" id="img2">
<input type="radio" name="slide" id="img3">
<img src="img/img1.jpeg" class="m1" alt="img1">
<img src="img/img2.jpeg" class="m2" alt="img2">
<img src="img/img3.jpeg" class="m3" alt="img3">
</div>
<div class="dots">
<label for="img1"></label>
<label for="img2"></label>
<label for="img3"></label>
</div>
</div>
I have simple slideshow with 3 images, I need to make background color of the checked button(obviously, each button refers to one img). I tried literally all possible solutions in the google, I would be really thankful if anyone could help me. Thanks in advance!
Here is my slideshow code:
.slider {
transform: translateX(20%);
display: inline-block;
position: relative;
width: 61%;
overflow: hidden;
box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px 0px;
}
.images {
display: flex;
width: 100%;
}
.images img {
width: 100%;
transition: all 0.15s ease;
}
.images input {
display: none;
}
.dots {
display: flex;
justify-content: center;
margin: 5px;
}
.dots label {
height: 15px;
width: 15px;
border-radius: 50%;
border: solid #13447E 3px;
cursor: pointer;
transition: all 0.15s ease;
margin: 5px;
}
#img1:checked ~ .m1 {
margin-left: 0;
}
#img2:checked ~ .m2 {
margin-left: -100%;
}
#img3:checked ~ .m3 {
margin-left: -200%;
}
<div class="slider">
<div class="images">
<input type="radio" name="slide" id="img1" checked>
<input type="radio" name="slide" id="img2">
<input type="radio" name="slide" id="img3">
<img src="img/img1.jpeg" class="m1" alt="img1">
<img src="img/img2.jpeg" class="m2" alt="img2">
<img src="img/img3.jpeg" class="m3" alt="img3">
</div>
<div class="dots">
<label for="img1"></label>
<label for="img2"></label>
<label for="img3"></label>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在标签之前设置单选按钮
Try to set radio button before label
这是一个带有一些JavaScript的解决方案:)
Here's a solution with a bit of javascript :)