gpt4 book ai didi

html - 使用 html 和 css 创建评级星

转载 作者:行者123 更新时间:2023-12-05 02:35:23 26 4
gpt4 key购买 nike

我想用我的 html 脚本创建一个评级星。如果我的 html 脚本像
<input type="radio" name="rating" id="rating-5"><label for="rating-5" class="fas fa-star"></label> 一样运行此 css 脚本,
但我想这样跑
<label for="rating-5" class="fas fa-star"> <input type="radio" name="rating" id="rating-5"> </label>
像下面的示例脚本和 css 不工作

例子:

{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: arial;
}

.star-rating input {
display: none;
}

.star-rating {
margin: 50px auto;
display: table;
width: 350px;
}

.star-rating label {
padding: 10px;
float: right;
font-size: 44px;
color: #eee;
}

.star-rating input:not(:checked)~label:hover,
.star-rating input:not(:checked)~label:hover~label {
color: #ffc107;
}

.star-rating input:checked {
color: #ffc107;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.10.2/css/all.css" />

<div class="star-rating">
<div class="star-input">
<label for="rating-5" class="fas fa-star">
<input type="radio" name="rating" id="rating-5"></label>
<label for="rating-4" class="fas fa-star">
<input type="radio" name="rating" id="rating-4"></label>
<label for="rating-3" class="fas fa-star">
<input type="radio" name="rating" id="rating-3"></label>
<label for="rating-2" class="fas fa-star">
<input type="radio" name="rating" id="rating-2"></label>
<label for="rating-1" class="fas fa-star">
<input type="radio" name="rating" id="rating-1"></label>
</div>
</div>

请帮助我的问题,谢谢,抱歉我的英语不好..

最佳答案

这可能是不使用 JS 的解决方案。

 .rating {
display: inline-block;
position: relative;
height: 50px;
line-height: 50px;
font-size: 25px;
}

.rating label {
position: absolute;
top: 0;
left: 0;
height: 100%;
cursor: pointer;
}

.rating label:last-child {
position: static;
}

.rating label:nth-child(1) {
z-index: 5;
}

.rating label:nth-child(2) {
z-index: 4;
}

.rating label:nth-child(3) {
z-index: 3;
}

.rating label:nth-child(4) {
z-index: 2;
}

.rating label:nth-child(5) {
z-index: 1;
}

.rating label input {
position: absolute;
top: 0;
left: 0;
opacity: 0;
}

.rating label .icon {
float: left;
color: transparent;
}

.rating label:last-child .icon {
color: #000;
}

.rating:not(:hover) label input:checked ~ .icon,
.rating:hover label:hover input ~ .icon {
color: #ffa904;
}

.rating label input:focus:not(:checked) ~ .icon:last-child {
color: #000;
text-shadow: 0 0 5px #ffa904;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.10.2/css/all.css" />
<form class="rating">
<label>
<input type="radio" name="stars" value="1" />
<span class="fa fa-star icon"></span>
</label>
<label>
<input type="radio" name="stars" value="2" />
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
</label>
<label>
<input type="radio" name="stars" value="3" />
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
</label>
<label>
<input type="radio" name="stars" value="4" />
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
</label>
<label>
<input type="radio" name="stars" value="5" />
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
<span class="fa fa-star icon"></span>
</label>
</form>

关于html - 使用 html 和 css 创建评级星,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70588824/

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