使用before,after伪元素更改input radio/checkbox样式

之所以记录,是为了以后自己查找起来方便。

先上效果图: 

效果图

html布局:

           <input type="radio" name="payway" class="radio-type" id="surplus" />

           <label for="surplus">余额支付</label>

          <input type="radio" name="payway" class="radio-type" id="wechat" />

           <label for="wechat">微信支付</label>

css样式:

.radio-type{

  width: 14px;

  height: 14px;

  position: relative;

  vertical-align: sub;

}

.radio-type:before{

    content: '';

    width: 12px;

    height: 12px;

    border: 1px solid #858585;

    display: inline-block;

    border-radius: 50%;

    vertical-align: sub;

    background-color: #fff;

}

.radio-type:checked:before{

    content: '';

    width: 12px;

    height: 12px;

    border: 1px solid #FF6700;

    background:#FF6700;

    display: inline-block;

    border-radius: 50%;

    vertical-align: sub;

}

.radio-type:checked:after{

    content: '';

    width: 7px;

    height:3px;

    border: 2px solid white;

    text-align: center;

    display: block;

    position: absolute;

    top: 3px;

    left:2px;

    vertical-align: sub;

    border-top: transparent;

    border-right: transparent;

    transform: rotate(-45deg);

}

/* 如果想要选中框所对应的文字也变色*/

.radio-type:checked+label{ color:#ff6700;}


同样的写法 可自定义checkbox的样式~~


2.在vue中如何判断input框是否选中?----用v-model


图一
图二
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,721评论 0 8
  • 不会用代码框,所以看着有些乱套,,,,html部分 <!DOCTYPE html> 迅雷看看 ...
    这就是个帅气的名字阅读 1,583评论 0 0
  • 这篇文字里我会介绍50 个便于使用的 CSS2/CSS3 代码片段给所有的WEB专业人员. 选择IDE开发环境来存...
    JamHsiao_aaa4阅读 1,316评论 0 3
  • 字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般...
    米塔塔阅读 601评论 1 12
  • 这几天,培训我们的主任都在教授我们恒大的三十六条准则,其实之前对这些理论是满不屑的,我们上学接触了那么多理论,...
    控卫阅读 801评论 2 0