美化复选框(给复选框添加样式)

本文介绍了如何使用CSS来美化复选框,包括改变背景颜色等样式,提供了在线演示和本地代码下载,帮助读者实现自定义的复选框设计。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在线演示
本地代码下载

这里写图片描述

复选框的背景颜色都是可以更改,具体参考css样式来更改。

html:

<input type="checkbox" id="awesome" autofocus /><!--自动获得焦点  -->
<label for="awesome">Awesome!</label>
<br />
<input type="checkbox" id="awesome2" checked /><!-- 默认勾选 -->
<label for="awesome2">Awesome!</label>
<br />
<input type="checkbox" id="awesome3" disabled /><!-- 禁止勾选 -->
<label for="awesome3">Awesome!</label>
<br />
<input type="checkbox" id="awesome4" checked disabled /><!--默认勾选上,禁止勾选  -->
<label for="awesome4">Awesome!</label>

CSS:

<style>
    body { font: 150%/1.6 sans-serif;} 
    input[type="checkbox"] {
        position: absolute;
        clip: rect(0, 0, 0, 0);
    }

    input[type="checkbox"]+label::before {
        content: '\a0';
        display: inline-block;
        vertical-align: .2em;
        width: .8em;
        height: .8em;
        margin-right: .2em;
        border-radius: .2em;
        background: silver;
        text-indent: .15em;
        line-height: .65;
        background-color: red;
    }

    input[type="checkbox"]:checked+label::before {
        content: '\2713';
        background: yellowgreen;
    }

    input[type="checkbox"]:focus+label::before {
        box-shadow: 0 0 .1em .1em #58a;
        background-color: pink;
    }

    input[type="checkbox"]:disabled+label::before {
        background: gray;
        box-shadow: none;
        color: #555;
        cursor: not-allowed;
    }
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值