zoukankan      html  css  js  c++  java
  • HTML复选框checkbox默认样式修改

    此方法可以将复选框的默认样式替换成任意样式。如图: 
    未选择:未被选中

    选择时:选中

    思路:将复选框隐藏,利用lebal元素的焦点传递特性,用lebal的样式替代复选框。

    代码如下:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>checkbox css change</title>
    <style type="text/css">
    input[type="checkbox"] + label {
        cursor: pointer;
        font-size: 1em;
    }
    [id^="checkbox-"] + label {
        background-color: #ffffff;
        border: 1px solid #666666;
        box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
        padding: 9px;
        border-radius: 3px;
        display: inline-block;
        vertical-align: middle;
    }
    [id^="checkbox-"] + label:active {
        box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px 1px 3px rgba(0,0,0,0.1);
    }
    [id="checkbox-1"]:checked + label {
        background-color: #F47164;
        border: 1px solid #F47164;
    }
    [id="checkbox-2"]:checked + label {
        background-color: #84CBC5;
        border: 1px solid #84CBC5;
    }
    [id="checkbox-3"]:checked + label {
        background-color: #F8D25D;
        border: 1px solid #F8D25D;
    }
    </style>
    </head>
    <body>
        <label style="margin-left: 55px; margin-right: 16px;">状态:</label>
        <input type="checkbox" value="0" class="check_view_state"
            id="checkbox-1" style="display: none;">
        <label for="checkbox-1"></label>
        <span class="status">未读</span>
    
        <input type="checkbox" value="1" class="check_view_state"
            id="checkbox-2" style="display: none;">
        <label for="checkbox-2"></label>
        <span class="status">已读</span>
    
        <input type="checkbox" value="2" class="check_view_state"
            id="checkbox-3" style="display: none;">
        <label for="checkbox-3"></label>
        <span class="status">未授权</span>
    </body>
    </html>
  • 相关阅读:
    POJ 2234 Matches Game 尼姆博弈
    复杂问题的简单抽象:魔兽世界中的兔子们
    POJ 2368 巴什博奕
    POJ 1067 取石子游戏 威佐夫博弈
    Codeforces 704A Thor 队列模拟
    Codeforces 703B Mishka and trip
    P1447 [NOI2010]能量采集
    P2652 同花顺
    P2034 选择数字 / P2627 [USACO11OPEN]Mowing the Lawn G
    P2515 [HAOI2010]软件安装
  • 原文地址:https://www.cnblogs.com/chang229/p/6549238.html
Copyright © 2011-2022 走看看