【发布时间】:2020-11-08 11:08:43
【问题描述】:
我想要做的是让用户在整个评分范围内单击任何数字(每个数字都作为单选按钮),并且仅在该数字周围设置设计的背景颜色。但是,正如我在下面演示的那样,例如,当用户单击 #1 时,它会更改刻度中每个单选按钮的背景颜色。如何将其应用于每个人?
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
body{
margin: 0px;
padding: 0px;
background-color: bisque;
overflow: hidden;
}
.head{
text-align: center;
transform: translate(20px, 150px);
}
.rating{
transform: translate(320px, 200px);
}
.rating label{
cursor: pointer;
margin-right: 30px;
border: 1px solid #000;
border-radius: 25px;
padding: 5px 10px;
background-color: white;
}
.rating input{
display: none;
}
.labels{
display: flex;
list-style: none;
}
input#rate1:checked ~ label{
background-color: blue;
}
.bottom{
transform: translate(300px, 150px);
}
</style>
</head>
<body>
<div class="head">
<h1>On a Scale From 0-10, How Are You Feeling?</h1>
</div>
<div class="labels">
<ul>
<li>Rock Bottom</li>
<li>Terrible</li>
</ul>
</div>
<div class="rating">
<input type="radio" name="rating" id="rate0"><label for="rate0"
>0</label>
<input type="radio" name="rating" id="rate1"><label for="rate1"
>1</label>
<input type="radio" name="rating" id="rate2"><label for="rate2"
>2</label>
<input type="radio" name="rating" id="rate3"><label for="rate3"
>3</label>
<input type="radio" name="rating" id="rate4"><label for="rate4"
>4</label>
<input type="radio" name="rating" id="rate5"><label for="rate5"
>5</label>
<input type="radio" name="rating" id="rate6"><label for="rate6"
>6</label>
<input type="radio" name="rating" id="rate7"><label for="rate7"
>7</label>
<input type="radio" name="rating" id="rate8"><label for="rate8"
>8</label>
<input type="radio" name="rating" id="rate9"><label for="rate9"
>9</label>
<input type="radio" name="rating" id="rate10"><label for="rate10"
>10</label>
<div class="bottom">
<a href="index.html"><button class="btn1">Next</button></a>
</div>
</div>
</body>
</html>
【问题讨论】:
-
你好。你已经得到了你的问题的答案。请将所提供的任何对您有帮助的答案视为已解决。谢谢!
标签: html css radio-button