html滚动选择框代码,如何使用最简单纯Css代码美化checkbox复选框、radios单选框和滑动按钮...

最简洁的代码美化复选框、单选框和滑动按钮

效果预览

bV0dUt?w=261&h=66

1. 复选框

.switch {

margin: 20px 20px 0 0;

display: flex;

align-items: center;

width: auto;

}

.checkbox-input {

display: none

}

.checkbox {

-webkit-transition: background-color 0.3s;

transition: background-color 0.3s;

background-color: #fff;

border: 1px solid #d7d7d7;

border-radius: 3px;

width: 16px;

height: 16px;

vertical-align:middle;

margin: 0 5px;

}

.checkbox-input:checked+.checkbox {

background-color: #57ad68;

}

.checkbox-input:checked+.checkbox:after {

content: "\2714";

display: inline-block;

height: 100%;

width: 100%;

color: #fff;

text-align: center;

line-height: 16px;

font-size: 12px;

box-shadow: 0 0 4px #57ad68;

}

Hello

2. 单选框

.switch {

display: flex;

align-items: center;

width: auto;

float: left;

}

.radio-beauty-container .radio-beauty {

width: 16px;

height: 16px;

box-sizing: border-box;

display: inline-block;

border: 1px solid #d7d7d7;

margin: 0 5px;

border-radius: 50%;

transition: 0.2s;

}

.radio-beauty-container input[type="radio"]:checked+.radio-beauty {

border: solid 1px green;

padding: 3px;

background-color: green;

background-clip: content-box;

box-shadow: inset 0 0 1px rgba(0,128,0, 0.2), 0 0 3px green;

}

radio2

radio3

3. 滑动按钮

.switch-slide-label {

display: block;

width: 34px;

height: 18px;

background: #ccc;

border-radius: 30px;

cursor: pointer;

position: relative;

-webkit-transition: 0.3s ease;

transition: 0.3s ease;

}

.switch-slide-label:after {

content: '';

display: block;

width: 16px;

height: 16px;

border-radius: 100%;

background: #fff;

box-shadow: 0 1px 1px rgba(0, 0, 0, .1);

position: absolute;

left: 1px;

top: 1px;

-webkit-transform: translateZ(0);

transform: translateZ(0);

-webkit-transition:0.3s ease;

transition:0.3s ease;

}

.switch-slide input:checked+label {

background: #34bf49;

transition: 0.3s ease;

}

.switch-slide input:checked+label:after {

left: 17px;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当然可以使用 CSS 美化多选框checkbox)和单选框radio)。以下是一个简单的示例: HTML 代码: ```html <label class="checkbox"> <input type="checkbox"> <span class="checkmark"></span> Checkbox 1 </label> <label class="radio"> <input type="radio" name="radio"> <span class="checkmark"></span> Radio 1 </label> <label class="radio"> <input type="radio" name="radio"> <span class="checkmark"></span> Radio 2 </label> ``` CSS 代码: ```css /* 隐藏默认的 checkboxradio */ input[type="checkbox"], input[type="radio"] { display: none; } /* 定义 checkboxradio 的样式 */ .checkmark { display: inline-block; width: 20px; height: 20px; border: 1px solid #999; border-radius: 5px; cursor: pointer; position: relative; } /* 定义被选中的 checkboxradio 的样式 */ .checkmark::after { content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 10px; height: 10px; background-color: #999; border-radius: 50%; display: none; } input[type="checkbox"]:checked + .checkmark::after { display: block; } input[type="radio"]:checked + .checkmark::after { display: block; } /* 定义 label 的样式 */ label { display: block; margin-bottom: 10px; } /* 定义 checkboxradio 的父元素的样式 */ .checkbox, .radio { display: inline-block; vertical-align: top; margin-right: 20px; } /* 定义 checkboxradio 的文本样式 */ .checkbox span, .radio span { margin-left: 10px; font-size: 14px; } ``` 你可以根据需要调整样式,达到想要的美化效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值