css input checkbox和radio样式美化
参考:https://segmentfault.com/a/1190000004553258
http://www.haorooms.com/post/css_mh_ck_radio
思路都一样的,先把radio,checkbox按钮透明度opacity设置为0,然后,外层用span包裹,就实现了美化功能。
html代码:
<span class="init-radio-style">
<input type="radio" name="productType" id="po1" value="_90" class="radio-class">
</span>
<label for="po1">90天项目</label> scss 代码:
.init-radio-style {
width: 24px;
height: 24px;
padding-top: 3px;
cursor: pointer;
text-align: center;
background: url("/images/icons/spr.png") no-repeat 0 -209px;
&.on {
background-position: 0 -233px;
}
.radio-class {
opacity: 0;
cursor: pointer;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
} JS代码:
//初始化radio
$('.init-radio-style').on('click',function() {
var $this=$(this);
$('.init-radio-style').removeClass('on');
$this.addClass("on");
});
checkbox方法一样:
html
<div class="piaochecked on_check">
<input name="need_inv" type="checkbox" style="height:20px;width:20px;" class="radioclass input" value="1">
</div>
css :
.piaochecked {
width: 20px;
height: 20px;
float: left;
cursor: pointer;
margin-left: 10px;
text-align: center;
background-image: url(images/checkbox_01.gif);
background-repeat: no-repeat;
background-position: 0 0;
}
.on_check {
background-position: 0 -21px;
}
.radioclass {
opacity: 0;
cursor: pointer;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
}
因为是可以多选的,所以对其class做toggle就可以了,因为jquery新版本已经废弃了toggle事件,只保留toggle方法。所有我们要自己写toggle写法如下:
注:默认input checkbox的选中状态和外面父级的div的class是一致的。
$(".piaochecked").on("click",function(){
$(this).hasClass("on_check")? $(this).removeClass("on_check"):$(this).addClass("on_check");
//或者这么写
// $(this).toggleClass( "on_check" );
})
css input checkbox和radio样式美化的更多相关文章
- Css实现checkbox及radio样式自定义
前言 checkbox和radio样式自定义在网页中是很常见的, 比如在进行表单输入时性别的选择,用户注册时选择已阅读用户协议.随着用户对产品体验要求越来越高,我们都会对checkbox和radio重 ...
- css自定义checkbox和radio样式
很常见的问题,也有许多人写过类似的文章,自己写来记录下 css代码如下: #myCheck + label,.myRadio + label{ width:16px; height:16px; bor ...
- input美化 checkbox和radio样式
input美化 checkbox和radio样式 看惯了input[checkbox]和input[radio]默认样式,有没有想要改变一下呢?比如下面的样式: 比起html默认的样式,上图这些 ...
- HTML的checkbox和radio的美化
checkbox和radio的美化 checkbox: <style type="text/css"> input[type="checkbox"] ...
- div仿checkbox表单样式美化及功能
div仿checkbox表单样式美化及功能(checkbox的样式不好看)素材在底部: 效果图: window.css .bj { position: absolute; top: 0; left: ...
- 自定义checkbox, radio样式
17.2.25.nimil 今天开始做百度前端学院的任务,第一个是自定义checkbox, radio样式. checkbox和radio两个标签是不可以改变样式的,background-color. ...
- 表单:checkbox、radio样式(用图片换掉默认样式)
checkbox.radio样式(用图片换掉默认样式) <!doctype html> <html> <head> <meta charset="u ...
- 自定义checkbox, radio样式总结
任务目的 深入了解html label标签 了解CSS边框.背景.伪元素.伪类(注意和伪元素区分)等属性的设置 了解CSS中常见的雪碧图,并能自己制作使用雪碧图 任务描述 参考 样例(点击查看),实现 ...
- css input checkbox复选框控件 样式美化的多种方案
checkbox复选框可能是网站中常用的html元素,但大多数人并不满意它的默认样式,这篇文章就讲讲如何实现input checkbox复选框控件 样式美化效果. 资源网站大全 https://55w ...
随机推荐
- elasticsearch installation guide
UBUNTU 14.04 LTS 安装 elasticseach同步MYSQL表并实现中文搜索 ==================================================== ...
- 学习Spring(二) 调用静态工厂方法创建Bean
1,创建抽象的产品类 package com.robert.spring.shop; public abstract class Product { } 2,创建具体产品类 package com.r ...
- GisUtil工具类:将WKT(wellKnownText)文本转换为ElasticSearch识别的空间对象字符串形式
ElasticSearch中的Geo Shape Type: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/mapping-g ...
- HashMap Hashtable区别
http://blog.csdn.net/java2000_net/archive/2008/06/05/2512510.aspx 我们先看2个类的定义 public class Hashtable ...
- python初识第二篇
python 编码: 第一次编程有时候会遇到乱码的情况,就可以通过以下的情况来解决 在Windows中默认的就是gbk编码,如果在代码头两部定义utf-8,系统还会按照系统的方式来定义. python ...
- 1.值得推荐的C/C++框架和库 (转)
值得学习的C语言开源项目 - 1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的 ...
- Non Lasting Storage File System、procfs、sysfs
catalog . 引言 . proc文件系统 . 简单的文件系统 . sysfs 0. 引言 传统上,文件系统用于在块设备上持久存储数据,但也可以使用文件系统来组织.提供.交换并不存储在块设备上的信 ...
- tmux/screen里面如何用鼠标滚轮来卷动窗口内容
tmux里面用鼠标滚轮来卷动窗口内容 在 tmux里面,因为每个窗口(tmux window)的历史内容已经被tmux接管了,所以原来console/terminal提供的Shift+PgUp/PgD ...
- ConurrentHashMap和Hashtable的区别
转自:http://www.importnew.com/7166.html 集合类是Java API的核心,但是我觉得要用好它们是一种艺术.我总结了一些个人的经验,譬如使用ArrayList能够提高性 ...
- android toast几种使用方法
toast经常会用到,今天做个总结,特别是自定义toast的布局,值得一看. 一.默认展示 // 第一个参数:当前的上下文环境.可用getApplicationContext()或this // 第二 ...