<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 下面这段CSS代码定义了range控件的样式 -->
<style>
/* 隐藏range控件默认样式 */
[type="range"] {
-webkit-appearance: none;
appearance: none;
margin: 0;
outline: 0;
background-color: transparent;
width: 500px;
}
/* 定义range控件轨道的样式 */
[type="range"]::-webkit-slider-runnable-track {
height: 4px;
background: #eee;
}
/* 定义range控件容器的样式 */
[type="range" i]::-webkit-slider-container {
height: 20px;
overflow: hidden;
}
/* 定义range控件拇指的样式 */
[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #f44336;
border: 1px solid transparent;
margin-top: -8px;
/* 使用border-image属性给拇指添加渐变边框 */
border-image: linear-gradient(#f44336, #f44336) 0 fill / 8 20 8 0 / 0px 0px 0 2000px;
}
</style>
</head>
<body>
<!-- 在页面上添加一个range控件-->
<input type="range" min="0" max="100" value="50">
</body>
</html>
htmlcss更改input[range]滑块颜色和背景颜色示例代码纯css实现滑块控件上代码,并且附上代码解释
于 2023-04-17 14:54:56 首次发布