input标签中的radio和checkbox是很表单中常用的类型,大多时候,默认样式并不能满足我们的需求,所以有了此篇。

自定义样式,由此开启:

html:

<div class="questionBlock3">
<h6>2)请问你喜欢哪种水果?</h6>
<div class="answerRadioBox">
<label><input name="Fruit" type="radio" value="" /><font>苹果</font></label>
<label><input name="Fruit" type="radio" value="" /><font>苹果2</font> </label>
<label><input name="Fruit" type="radio" value="" /><font>苹果3</font></label>
<label><input name="Fruit" type="radio" value="" /><font>苹果4</font></label>
</div>
</div> <div class="questionBlock4">
<h6>2)请问你喜欢哪些水果?</h6>
<div class="answerCheckBox">
<label><input name="demoCheck" type="checkbox" value="" /><font>苹果 </font></label>
<label><input name="demoCheck" type="checkbox" value="" /><font>苹果2 </font></label>
<label><input name="demoCheck" type="checkbox" value="" /><font>苹果3 </font></label>
<label><input name="demoCheck" type="checkbox" value="" /><font>苹果4 </font></label>
<label><input name="demoCheck" type="checkbox" value="" /><font>苹果5</font></label>
<label><input name="demoCheck" type="checkbox" value="" /><font>苹果6</font></label>
</div>
</div>

css:

.answerRadioBox,.answerCheckBox{
width: 100%;
height: auto;
color: #fff;
font-size: 0;
padding:0.6rem 0 0.3rem 0;
border-bottom: 1px solid #fff;
} .answerRadioBox label,.answerCheckBox label{
width: 25%;
padding:0.2rem 0;
font-size: 0.6rem;
display: inline-block;
position: relative;
} .answerRadioBox label font,.answerCheckBox label font{
padding-left: 0.8rem;
} .answerRadioBox input[type="radio"] + font::before {
content: "\a0"; /*不换行空格*/
display: inline-block;
position: absolute;
top:50%;
left:0;
transform: translateY(-50%);
width: 0.56rem;
height: 0.56rem;
border-radius: 50%;
border: 1px solid #c9c9c9;
box-sizing: border-box;
} .answerRadioBox input[type="radio"]:checked + font::before {
background-color: #c9c9c9;
background-clip: content-box;
padding: 0.15em;
} .answerRadioBox input[type="radio"] {
position: absolute;
clip: rect(0, 0, 0, 0);
} .answerCheckBox input[type='checkbox']{
width: 0.56rem;
height: 0.56rem;
background: none;
-webkit-appearance: none;
border: 1px solid #c9c9c9;
border-radius: 2px;
outline: none;
position: absolute;
top: 50%;
left: 0;
transform: translateY(-50%);
} .answerCheckBox input[type=checkbox]:checked::before{
content: "\2713";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
color: #c9c9c9;
font-weight: bold;
text-align:center;
font-size:0.8rem;
line-height:0.5;
}

  

效果图如下:

  

主要是用到了伪元素,可以任意更换颜色,或者使用背景图片也可以。

“\2713”表示实体符号√,想了解更多可以去 html css特殊字符表 查阅

自定义radio、checkbox的样式的更多相关文章

  1. 自定义radio/checkbox样式

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. jquery mobile radio,checkbox button 样式设置

    <label><input type=checkbox ></label>,<input type=checkbox id="checkbox &q ...

  3. css 更改input radio checkbox的样式

    html <label> <input type="checkbox" class="colored-blue"> <span c ...

  4. 微信小程序 - radio/checkbox自定义组件

    更新 2019-01-26:首次发布 2019-01-27:增加默认取值选中radio/checkbox,checkbox需在onload取值 2019-01-28:增加radio取值不存在红色提示和 ...

  5. 微信小程序 - 更改radio和checkbox选中样式

    点击下载源码:示例-更改radio或checkbox选中样式

  6. 用纯css改变默认的radio和checkbox的样式

    利用css的label的伪类(::before)代替checkbox和radio效果: 优点:需要图片来调整选中前和选中后的样式,纯css搞定 缺点:兼容性,IE8以下不支持 在线例子: css改变默 ...

  7. css自定义 range radio select的样式滑轮,按钮,选择框

    写在前面: 之前踩坑css的时候,遇到滑轮,按钮,选择框这类型的东西,为了页面效果,总是需要自定义他们的样式,而不使用他们的默认样式.当时写的时候,我也是蛮头疼的,弄了个demo,链接在下面.对此做个 ...

  8. CSS3和jQuery实现的自定义美化Checkbox和Radiobox

    现在经常可以在网络上看到一些非常奇特的表单元素,例如Checkbox复选框和Radiobox单选框,浏览器默认的样式确实是太丑了,而且更让人蛋疼的是各个浏览器的样式还不统一,考虑到现在越来越多的用户使 ...

  9. 自定义常用input表单元素二:纯css实现自定义radio单选按钮

    这是接着上一篇纯css自定义复选框checkbox的第二篇,自定义一个radio单选按钮,同样,采用css伪类和"+"css选择器为思路,下面是预览图: 下面直入主题放代码:HTM ...

  10. CSS3和jQuery实现的自定义美化Checkbox

    效果图: 是不是比默认的好看多了,个人的审美观应该还是可以的. 当然我们可以在这里查看DEMO演示. 接下来我们一起来看看实现这款美化版Checkbox的源代码.主要思路是利用隐藏原来的checkbo ...

随机推荐

  1. 如何使用会声会影制作动态logo字幕

    日常生活中大家在参加一些婚礼.聚会的时候,LED屏幕上播放的视频里面常常会有一行字,它随着视频的播放自己也在不断地改变颜色,非常醒目.想必大家也想把这种动态文字用在自己的视频中,为视频增添亮点.那么今 ...

  2. 企业级LINUX自动化运维工具Ansible实战课程下载

    什么是Ansible? Ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量 ...

  3. T - Permutation 题解(思维+dp)

    题目链接 题目大意 给你一个数字n和长为n-1个字符串 字符串包含'<','>' 若s[i]='<' 则代表a[i]<a[i+1] 若s[i]='>' 则代表a[i]&g ...

  4. 深度学习(一):Python神经网络——手写数字识别

    声明:本文章为阅读书籍<Python神经网络编程>而来,代码与书中略有差异,书籍封面: 源码 若要本地运行,请更改源码中图片与数据集的位置,环境为 Python3.6x. 1 import ...

  5. 区块链V1版本实现之一

    1. 程序地址:https://gitee.com/Jame_sz/beijing_go_term2.git 2. 程序编写流程: //1. 定义结构(区块头的字段比正常的少) //>1. 前区 ...

  6. JS基础入门,知识点总结归纳图

  7. 关于热力图的loss的一点感想

    网络的输出的热力图和gt相减的差矩阵,求其最大特征值的平方作为loss. 若图像h w不相等,可以使用奇异值代替特征值.奇异值往往对应着矩阵中隐含的重要信息,且重要性和奇异值大小正相关.每个矩阵A都可 ...

  8. 帆软用工具测试超链接打开弹窗(iframe嵌套),解决js传参带中文传递有乱码问题

    1.新建超链接 随意点击一个单元格右击,选择 超级链接 2.在弹出的窗口中选择JavaScript脚本 如图: 其中红框框出的是几个要点   ,左边的就不讲了,右上角的参数cc是设置了公式remote ...

  9. Windows 10系统运维之OpenSSH

    随着PowerShell和OpenSSH的日渐成熟,在客户终端Windows居多的运维之中,使用Win32-OpenSSH和Powershell来管理一些客户机变成了相当实用的一种解决方案. Open ...

  10. bypass disable_function

    windows 1.com组件绕过 <?php$command=$_POST['a'];$wsh = new COM('WScript.shell'); // 生成一个COM对象 Shell.A ...