我正在尝试改编https://codepen.io/hesguru/pen/BaybqXv中的代码,以创建一个带有提交按钮的反应性星级表,该按钮可以传递给我的python后端。但是,我无法显示“提交”按钮,我知道这可能是由于CSS导致的,但是还无法解决该问题。 (This is how it currently appears)如何使“提交”按钮出现并起作用?
.rate {
float: left;
height: 46px;
padding: 0 10px;
}
.rate:not(:checked) > input {
position:absolute;
top:-9999px;
}
.rate:not(:checked) > label {
float:right;
overflow:hidden;
white-space:nowrap;
cursor:pointer;
font-size:30px;
color:#ccc;
}
.rate:not(:checked) > label:before {
content: '★ ';
}
.rate > input:checked ~ label {
color: #ffc700;
}
.rate:not(:checked) > label:hover,
.rate:not(:checked) > label:hover ~ label {
color: #deb217;
}
.rate > input:checked + label:hover,
.rate > input:checked + label:hover ~ label,
.rate > input:checked ~ label:hover,
.rate > input:checked ~ label:hover ~ label,
.rate > label:hover ~ input:checked ~ label {
color: #c59b08;
} width:1em;
<form action="/r" method="POST" class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="5">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="4">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="3">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="2">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="1">1 star</label>
<input type="submit" id="sub" value="Submit">
</form>
答案 0 :(得分:0)
您描述的问题是由以下选择器引起的:
.rate:not(:checked)>input
这将在<input>
.rate
元素中选择 all 个<form>
元素(其本身永远不会与:checked
伪类匹配) ,而不考虑<input>
的类型。
如果将该行修改为以下内容:
.rate > input[type=radio]
然后,它将仅匹配与<input>
匹配的type="radio"
个元素;并删除(完全无意义的伪类)::not(:checked)
,因为<form>
元素可以-并且应该-永远不会匹配该选择器:
.rate {
float: left;
height: 46px;
padding: 0 10px;
}
.rate > input[type=radio] {
position: absolute;
top: -9999px;
}
.rate:not(:checked)>label {
float: right;
overflow: hidden;
white-space: nowrap;
cursor: pointer;
font-size: 30px;
color: #ccc;
}
.rate:not(:checked)>label:before {
content: '★ ';
}
.rate>input:checked~label {
color: #ffc700;
}
.rate:not(:checked)>label:hover,
.rate:not(:checked)>label:hover~label {
color: #deb217;
}
.rate>input:checked+label:hover,
.rate>input:checked+label:hover~label,
.rate>input:checked~label:hover,
.rate>input:checked~label:hover~label,
.rate>label:hover~input:checked~label {
color: #c59b08;
width: 1em;
}
<form action="/r" method="POST" class="rate">
<input type="radio" id="star5" name="rate" value="5" />
<label for="star5" title="5">5 stars</label>
<input type="radio" id="star4" name="rate" value="4" />
<label for="star4" title="4">4 stars</label>
<input type="radio" id="star3" name="rate" value="3" />
<label for="star3" title="3">3 stars</label>
<input type="radio" id="star2" name="rate" value="2" />
<label for="star2" title="2">2 stars</label>
<input type="radio" id="star1" name="rate" value="1" />
<label for="star1" title="1">1 star</label>
<input type="submit" id="sub" value="Submit">
</form>