gpt4 book ai didi

html - 如何确保一个 radio 表格不检查另一个 radio 表格

转载 作者:行者123 更新时间:2023-11-28 06:05:30 27 4
gpt4 key购买 nike

我找到了一个纯 CSS 星级系统,但是对于给定的代码,我只能在每个页面上使用一个星级系统。我试过更改类(class)名称,但不幸的是,第二个星级评分表在按下时会检查第一个星级评分表。有什么办法解决这个问题吗?

.rating { 
border: none;
float: left;
}

.rating > input { display: none; }
.rating > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}

.rating > .half:before {
content: "\f089";
position: absolute;
}

.rating > label {
color: #ddd;
float: right;
}

/***** CSS Magic to Highlight Stars on Hover *****/

.rating > input:checked ~ label, /* show gold star when clicked */
.rating:not(:checked) > label:hover, /* hover current star */
.rating:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */

.rating > input:checked + label:hover, /* hover current star when changing rating */
.rating > input:checked ~ label:hover,
.rating > label:hover ~ input:checked ~ label, /* lighten current selection */
.rating > input:checked ~ label:hover ~ label { color: #FFED85; }

HTML

<form class="form-class" id="starform">               
<fieldset class="rating">
<input type="radio" id="star2" name="rating" value="2"/>
<label class="full" for="star2" title="2 stars"></label>

<input type="radio" id="star1" name="rating" value="1"/>
<label class="full" for="star1" title="1 star"></label>
</fieldset>
</form>

<form class="form-class" id="starformtwo">
<fieldset class="ratingtwo">
<input type="radio" id="star2-2" name="ratingtwo" value="2"/>
<label class="full" for="star2-2" title="2 stars"></label>

<input type="radio" id="star1-2" name="ratingtwo" value="1"/>
<label class="full" for="star1-2" title="1 star"></label>
</fieldset>
</form>

最佳答案

你是这个意思吗?

.ratings { 
border: none;
float: left;
}

.ratings > input { display: none; }
.ratings > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}

.ratings > .half:before {
content: "\f089";
position: absolute;
}

.ratings > label {
color: #ddd;
float: right;
}

/***** CSS Magic to Highlight Stars on Hover *****/

.ratings > input:checked ~ label, /* show gold star when clicked */
.ratings:not(:checked) > label:hover, /* hover current star */
.ratings:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */

.ratings > input:checked + label:hover, /* hover current star when changing rating */
.ratings > input:checked ~ label:hover,
.ratings > label:hover ~ input:checked ~ label, /* lighten current selection */
.ratings > input:checked ~ label:hover ~ label { color: #FFED85; }

.ratingtwo {
border: none;
float: left;
}

.ratingtwo > input { display: none; }
.ratingtwo > label:before {
margin: 5px;
font-size: 1.25em;
font-family: FontAwesome;
display: inline-block;
content: "\f005";
}

.ratingtwo > .half:before {
content: "\f089";
position: absolute;
}

.ratingtwo > label {
color: #ddd;
float: right;
}

/***** CSS Magic to Highlight Stars on Hover *****/

.ratingtwo > input:checked ~ label, /* show gold star when clicked */
.ratingtwo:not(:checked) > label:hover, /* hover current star */
.ratingtwo:not(:checked) > label:hover ~ label { color: #FFD700; } /* hover previous stars in list */

.ratingstwo > input:checked + label:hover, /* hover current star when changing rating */
.ratingstwo > input:checked ~ label:hover,
.ratingtwo > label:hover ~ input:checked ~ label, /* lighten current selection */
.ratingtwo > input:checked ~ label:hover ~ label { color: #FFED85; }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<form class="form-class" id="starform">
<fieldset class="ratings">
<input type="radio" id="star2" name="rating" value="2"/>
<label class="full" for="star2" title="2 stars"></label>

<input type="radio" id="star1" name="rating" value="1"/>
<label class="full" for="star1" title="1 star"></label>
</fieldset>
</form>

<form class="form-class" id="starformtwo">
<fieldset class="ratingtwo">
<input type="radio" id="star2-2" name="ratingtwo" value="2"/>
<label class="full" for="star2-2" title="2 stars"></label>

<input type="radio" id="star1-2" name="ratingtwo" value="1"/>
<label class="full" for="star1-2" title="1 star"></label>
</fieldset>
</form>

或者您可以转到 jsfiddle:https://jsfiddle.net/rnpow2yz/

希望这段代码有效。

关于html - 如何确保一个 radio 表格不检查另一个 radio 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36481795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com