checkbox.gif
- 自定义选择框的边框
- 选中的效果
- hover上去的效果
<!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">
<script src="vue.min.js"></script>
<title>Document</title>
<style>
#app {
margin-left: 100px;
}
input {
visibility: hidden;
}
label {
user-select: none;
display: block;
height: 20px;
line-height: 20px;
position: relative;
}
label::before {
position: absolute;
left: -30px;
vertical-align: middle;
content: '';
display: inline-block;
width: 18px;
height: 18px;
border: 1px solid grey;
}
label:hover::before {
border-color: skyblue;
}
input:checked+label:hover::before {
border-color: red;
}
input:checked+label::before {
background-image: url(selected.png);
background-size: 100% 100%;
background-repeat: no-repeat;
}
</style>
</head>
<body>
<div id="app">
您已选中:{{checkedNames}}
<br>
<input type="checkbox" v-model="checkedNames" id="cxk" value="cxk">
<label for="cxk">篮球高手蔡徐坤</label>
<input type="checkbox" v-model="checkedNames" id="lzx" value="lzx">
<label for="lzx">时间刺客罗志祥</label>
</div>
<script>
let app = new Vue({
el: '#app',
data: {
checkedNames: [],
}
})
</script>
</body>
</html>
网友评论