• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

css如何改变默认的radio和checkbox的样式

php 搞代码 3年前 (2022-01-21) 50次浏览 已收录 0个评论

本篇文章给大家分享的是关于css如何改变默认的radio和checkbox的样式 ,内容很不错,有需要的朋友可以参考一下,希望可以帮助到大家。

利用css的label的伪类(::before)代替checkbox和radio效果:

  1. 优点:需要图片来调整选中前和选中后的样式,纯css搞定

  2. 缺点:兼容性,IE8以下不支持

代码:

<!DOCTYPE html><html><head>  <meta charset="UTF-8">  <meta http-equiv="X-UA-Compatible" content="ie=edge">  <title>css改变默认的radio和checkbox的样式</title>  <style>    input[type="radio"],    input[type='checkbox'] {      display: none;    }    input[type='radio']+label::before,    input[type='checkbox']+label::before {      content: '';      display: inline-block;      width: 15px;      height: 15px;      margin-right: 6px;      border-radius: 100%;      vertical-align: middle;      border: 1px solid #E4E4E4;      background: #FFFFFF;      background-image: url('https://i.loli.net/2018/07/20/5b517d0bf066a.png');      background-position: 0px 0px;    }    input[type='radio']:hover+label::before,    input[type='checkbox']:hover+label::before {      background-position: -15px 0px;    }    input[type='radio']:checked+label::before,    input[type='checkbox']:checked+label::before {      background-position: -15px -15px;    }  </style></head><body>  <p>单选框</p>  <input type="radio" name="sex" value="man" id="man" checked>  <label for="man">男</label>  <input type="radio" name="sex" value="female" id="female">  <label for="female">女</label>  <p>多选框</p>  <input type="checkbox" name="fruits" value="apple" id="apple" checked>  <label for="apple">苹果</label>  <input type="checkbox" name="fruits" value="orange" id="orange&<span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea>quot;>  <label for="orange">橙子</label></body></html>

相关推荐:

Css Sprite如何实现图像拼合技术

如何通过CSS的border属性为图片设置边框效果

以上就是css如何改变默认的radio和checkbox的样式的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:css如何改变默认的radio和checkbox的样式

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址