gpt4 book ai didi

html - 单击 Firefox 时纯 CSS 星级评级小部件聚焦于顶部

转载 作者:太空宇宙 更新时间:2023-11-04 15:18:56 24 4
gpt4 key购买 nike

我已经关注了这个 Star rating widget with pure CSS教程,即使它在 Chrome 和 Firefox 中工作正常。在 Firefox 中单击星标时,页面会一直滚动到顶部。就好像您在单击带有 href='#' 的数据。

关于如何防止这种情况的任何想法?以下是 HTML:

<fieldset class="rating">
<legend>Please rate:</legend>
<input type="radio" id="star5" name="rating" value="5" /><label for="star5" title="Rocks!">5 stars</label>
<input type="radio" id="star4" name="rating" value="4" /><label for="star4" title="Pretty good">4 stars</label>
<input type="radio" id="star3" name="rating" value="3" /><label for="star3" title="Meh">3 stars</label>
<input type="radio" id="star2" name="rating" value="2" /><label for="star2" title="Kinda bad">2 stars</label>
<input type="radio" id="star1" name="rating" value="1" /><label for="star1" title="Sucks big time">1 star</label>
</fieldset>

这里是 CSS:

.rating {
float:left;
}

/* :not(:checked) is a filter, so that browsers that don’t support :checked don’t
follow these rules. Every browser that supports :checked also supports :not(), so
it doesn’t make the test unnecessarily selective */
.rating:not(:checked) > input {
position:absolute;
top:-9999px;
clip:rect(0,0,0,0);
}

.rating:not(:checked) > label {
float:right;
width:1em;
padding:0 .1em;
overflow:hidden;
white-space:nowrap;
cursor:pointer;
font-size:200%;
line-height:1.2;
color:#ddd;
text-shadow:1px 1px #bbb, 2px 2px #666, .1em .1em .2em rgba(0,0,0,.5);
}

.rating:not(:checked) > label:before {
content: '★ ';
}

.rating > input:checked ~ label {
color: #f70;
text-shadow:1px 1px #c60, 2px 2px #940, .1em .1em .2em rgba(0,0,0,.5);
}

.rating:not(:checked) > label:hover,
.rating:not(:checked) > label:hover ~ label {
color: gold;
text-shadow:1px 1px goldenrod, 2px 2px #B57340, .1em .1em .2em rgba(0,0,0,.5);
}

.rating > input:checked + label:hover,
.rating > input:checked + label:hover ~ label,
.rating > input:checked ~ label:hover,
.rating > input:checked ~ label:hover ~ label,
.rating > label:hover ~ input:checked ~ label {
color: #ea0;
text-shadow:1px 1px goldenrod, 2px 2px #B57340, .1em .1em .2em rgba(0,0,0,.5);
}

.rating > label:active {
position:relative;
top:2px;
left:2px;
}

最佳答案

输入类型单选字段将绝对移动到顶部 -9999 像素。单击输入字段将被更改,firefox 会尝试滚动到它们。与其移动,不如尝试隐藏它们:

替换

.rating:not(:checked) > input {
position:absolute;
top:-9999px;
clip:rect(0,0,0,0);
}

.rating:not(:checked) > input {
display: none;
}

关于html - 单击 Firefox 时纯 CSS 星级评级小部件聚焦于顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11485834/

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