美文网首页
input为checkbox时的技巧

input为checkbox时的技巧

作者: 苍老师的眼泪 | 来源:发表于2022-03-20 02:11 被阅读0次
    checkbox.gif
    1. 自定义选择框的边框
    2. 选中的效果
    3. 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>
    

    相关文章

      网友评论

          本文标题:input为checkbox时的技巧

          本文链接:https://www.haomeiwen.com/subject/zvkodrtx.html