前端 - CSS 如何设置自动滚动定位的“安全”间距?_个人文章 - SegmentFault 思否
欢迎关注我的公众号:前端侦探介绍两个和滚动定位相关的 CSS 属性:scroll-padding和 scroll-margin在平时开发中,经常会碰到需要快速定位的问题,比如常见的锚点定位<l
顺晟科技
2022-09-13 14:03:01
279
1.设置radio样式
注意:radio的id要和对应的label 的for相同。
原理:使用 :checked+label 切换样式图片。checkbox也可以这么做。
CSS:
input[type=radio] {
float: left;
visibility: hidden;
}
label {
float: left;
width: 16px;
height: 15px;
margin: 18px 5px 0 0;
background: url(../images/arrow.png) no-repeat;
cursor: pointer;
}
.l1 {
background-position: -237px -184px;
background-size: 250px;
}
.l2 {
background-position: -236px -156px;
background-size: 250px;
}
#r1:checked + label {
background-position: -210px -184px;
}
#r2:checked + label {
background-position: -212px -156px;
}
HTML:
<div class="male"> <input type="radio" checked="checked" name="sexlist" id="r1" /> <label for="r1" class="l1"></label>男 </div> <div class="female"> <input type="radio" name="sexlist" id="r2" /> <label for="r2" class="l2"></label>女 </div>
效果:


2.进度条样式(摘自http://lab.tianyizone.com/demo/form/form_demo_css.html)
原理:为三个页面的进度条分别设置不同的value,由此切换背景图片。
CSS:
progress {display: block;width: 300px;height: 35px;margin-bottom:10px;-webkit-appearance:none;}
progress::-webkit-progress-bar { background: url(bg_step.png) no-repeat 0 0; }
progress::-webkit-progress-value { background: url(bg_step.png) no-repeat 0 -50px; }
progress[value="2"]::-webkit-progress-value { background-position: 0 -100px; }
progress[value="3"]::-webkit-progress-value { background-position: 0 -150px; }
HTML:
<progress max="3" value="2"></progress>
其中max定义完成值,value定义当前值。
效果:



17
2022-11
09
2022-11
19
2022-10
19
2022-10
12
2022-10
30
2022-09