html+css 实现多选按钮动画(input checkbox按钮)

前言:哈喽,大家好,今天给大家分享html+css 绚丽效果!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕

效果

多选

原理解析

1.纯css实现,没有js。点击事件是input的checked实现的。

通过input的checked实现点击效果

2.当点击的时候input自动添加checked,改变input后面的span元素来实现动画效果。

2.1 多选按钮的圆形实现,是通过input后面的span元素的伪类before和after实现的

多选按钮样式效果
效果图示绘制方法
代码图示绘制方法

2.2对号的实现,是通过input后面的span元素的伪类before和span元素的伪类after实现,并且旋转一定角度就实现了。

对号的实现原理图示

对号按钮代码效果

3.具体的变换参数,直接看代码,可以一键复制,查看效果

上代码,可以直接复制使用

目录

多选按钮动画目录

html

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

    <title>html+css 实现多选按钮动画(input checkbox按钮)</title>
    <link rel="stylesheet" href="./style.css">
</head>

<body>

    <div class="container">
        <h1 style="text-align: center;color:#382F45;margin-bottom: 50px;padding-top: 50px">html+css 实现多选按钮动画(input checkbox按钮)</h1>
        <div class="wrapper">
            <p>会给我三连吗?</p>
            <div class="input-box">
                <label>
                    <input type="checkbox" name="yes_no">
                    <span class="yes"></span>
                    必须滴
                </label>

            </div>
            <div class="input-box">
                <label>
                    <input type="checkbox" name="yes_no">
                    <span class="yes"></span>
                    一定给
                </label>
            </div>
            <div class="input-box">
                <label>
                    <input type="checkbox" name="yes_no">
                    <span class="yes"></span>
                    支持一波!
                </label>
            </div>
            <div class="input-box">
                <label>
                    <input type="checkbox" name="yes_no">
                    <span class="yes"></span>
                    点赞,收藏,关注!
                </label>
            </div>
            <div class="input-box">
                <label>
                    <input type="checkbox" name="yes_no">
                    <span class="yes"></span>
                    先收藏,以防找不到了!
                </label>
            </div>
        </div>

    </div>
</body>

</html>

css

*{
    /* 初始化 */
    margin: 0;
    padding: 0;
}
.container{
    min-height: 100vh;
    /* 渐变背景 */
    background: linear-gradient(200deg,#e4efe9,#93a5cf);
}

.wrapper{
    width: 600px;
    margin: 0 auto;
    background-color: #382f45;
    border-radius: 20px;
    /* 弹性布局 垂直排列 居中 */
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* 阴影 */
    box-shadow: 10px 10px 20px rgba(0,0,0,0.2);
    padding: 30px;
}
p{
    color: #fff;
    font-size: 40px;
    letter-spacing: 5px;
}
.input-box{
    display: flex;
    justify-content: space-between;
    margin-top: 50px;
    padding-left: 50px;
}
.input-box label{
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    font-size: 32px;
    color: #fff;
    letter-spacing: 5px;
}
.input-box label span{
    /* 相对定位 */
    position: relative;
    display: inline-block;
    width: 30px;
    height: 30px;
    margin-right: 15px;
    /* 设置过渡 */
    transition: 0.5s;
}
/*绘制多选按钮的方框*/
.input-box label span::before{
    content: "";
    /* 绝对定位 */
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 4px;
    background-color: #fff;
    /* 通过阴影的方式绘制上边框 */
    box-shadow: 0 -26px 0 #fff;
    transition: 0.5s;
}
.input-box label span::after{
    content: "";
    /* 绝对定位 */
    position: absolute;
    left: 0;
    bottom: 0;
    width: 4px;
    height: 100%;
    background-color: #fff;
    /* 通过阴影的方式绘制右边框 */
    box-shadow: 26px 0 0 #fff;
    transition: 0.5s;
}
.input-box label .radioSpan::before{
    height: 100%;
    border-radius: 50%;
    background-color: transparent;
    /* 通过阴影的方式绘制圆 */
    box-shadow: 0 0 0 4px #fff;
}
.input-box label .radioSpan::after{
    width: 0;
    height: 0;

}

.input-box input{
    display: none;
}
/*选中的操作*/
.input-box label input:checked ~ span.yes::before{
    background-color: #0f0;
    box-shadow: none;
    height: 4px;
    border-radius: 0;
}
.input-box label input:checked ~ span.yes::after{
    background-color: #0f0;
    box-shadow: none;
    width: 4px;
    height: 55%;
}
.input-box label input:checked ~ span.yes{
    border-radius: 0;
    transform: rotate(-45deg) translate(2px,-10px);
}

.input-box label input:checked ~ span.no::before{
    width:100%;
    height: 4px;
    background-color: #f00;
    box-shadow: none;
    border-radius: 0;
    transform: rotate(-45deg) translate(7px,-8px);
}
.input-box label input:checked ~ span.no::after{
    width: 4px;
    height: 100%;
    background-color: #f00;
    box-shadow: none;
    transform: rotate(-45deg) translate(7px,11px);
}

到此这篇文章就介绍到这了,更多精彩内容请关注本人以前的文章或继续浏览下面的文章,创作不易,如果能帮助到大家,希望大家多多支持宝码香车~💕

整理不易,点赞关注宝码香车

更多专栏订阅推荐:
👍 html+css+js 绚丽效果
💕 vue
✈️ Electron
⭐️ js
📝 字符串
✍️ 时间对象(Date())操作

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要使用jQuery UI实现多选按钮,你需要按照以下步骤进行操作: 步骤 1:引入jQuery和jQuery UI库 首先,在你的HTML文件中引入jQuery和jQuery UI库。可以通过CDN链接或本地文件引入,确保在使用jQuery UI之前先引入jQuery。 ```html <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css"> ``` 步骤 2:创建HTML元素 在HTML文件中创建一个容器元素,用于包含多选按钮组。 ```html <div id="multiSelectButtons"> <input type="checkbox" id="option1" /> <label for="option1">Option 1</label> <input type="checkbox" id="option2" /> <label for="option2">Option 2</label> <input type="checkbox" id="option3" /> <label for="option3">Option 3</label> </div> ``` 步骤 3:初始化多选按钮组件 在JavaScript代码中,使用`$(selector).buttonset()`方法来初始化多选按钮组件。 ```javascript $(function() { $("#multiSelectButtons").buttonset(); }); ``` 步骤 4:处理多选按钮的状态改变 如果需要对多选按钮的状态改变做出响应,可以使用jQuery的事件处理函数来监听状态改变事件。 ```javascript $(function() { $("#multiSelectButtons").buttonset(); $("input[type='checkbox']").on("change", function() { // 在这里执行多选按钮状态改变时的操作 if ($(this).is(":checked")) { console.log($(this).attr("id") + " is checked."); } else { console.log($(this).attr("id") + " is unchecked."); } }); }); ``` 以上就是使用jQuery UI实现多选按钮的基本步骤。你可以根据需要自定义样式和处理多选按钮状态改变的操作。详细的API文档和示例可以在[jQuery UI官方网站](https://jqueryui.com/button/#checkbox)上找到。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宝码香车

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值