纯CSS美化的checkbox 和 radio

简介:

html

复制代码
<!DOCTYPE HTML>
<html>
<head>

<title>纯CSS3实现自定义美化复选框和单选框</title>
<link rel="stylesheet" type="text/css" href="style2.css" />

</head>
<body>

<div id="holder">
    <div>
        <div class="tag">Checkbox Small</div>
        <input type="checkbox" id="checkbox-1-1" class="regular-checkbox" /><label for="checkbox-1-1"></label>
        <input type="checkbox" id="checkbox-1-2" class="regular-checkbox" /><label for="checkbox-1-2"></label>
        <input type="checkbox" id="checkbox-1-3" class="regular-checkbox" /><label for="checkbox-1-3"></label>
        <input type="checkbox" id="checkbox-1-4" class="regular-checkbox" /><label for="checkbox-1-4"></label>
    </div>
    <div>
        <div class="tag">Checkbox Big</div>
        <input type="checkbox" id="checkbox-2-1" class="regular-checkbox big-checkbox" /><label for="checkbox-2-1"></label>
        <input type="checkbox" id="checkbox-2-2" class="regular-checkbox big-checkbox" /><label for="checkbox-2-2"></label>
        <input type="checkbox" id="checkbox-2-3" class="regular-checkbox big-checkbox" /><label for="checkbox-2-3"></label>
        <input type="checkbox" id="checkbox-2-4" class="regular-checkbox big-checkbox" /><label for="checkbox-2-4"></label>
    </div>
    <div style="text-align:center;clear:both;margin:10px 0">
<script src="/gg_bd_ad_720x90.js" type="text/javascript"></script>
<script src="/follow.js" type="text/javascript"></script>
</div>
    <div>
        <div class="tag">Radio Small</div>
        <div class="button-holder">
            <input type="radio" id="radio-1-1" name="radio-1-set" class="regular-radio" checked /><label for="radio-1-1"></label><br />
            <input type="radio" id="radio-1-2" name="radio-1-set" class="regular-radio" /><label for="radio-1-2"></label><br />
            <input type="radio" id="radio-1-3" name="radio-1-set" class="regular-radio" /><label for="radio-1-3"></label><br />
            <input type="radio" id="radio-1-4" name="radio-1-set" class="regular-radio" /><label for="radio-1-4"></label><br />
        </div>
    </div>
    <div>
        <div class="tag">Radio Big</div>
        <div class="button-holder">
            <input type="radio" id="radio-2-1" name="radio-2-set" class="regular-radio big-radio" /><label for="radio-2-1"></label><br />
            <input type="radio" id="radio-2-2" name="radio-2-set" class="regular-radio big-radio" /><label for="radio-2-2"></label><br />
            <input type="radio" id="radio-2-3" name="radio-2-set" class="regular-radio big-radio" checked /><label for="radio-2-3"></label><br />
            <input type="radio" id="radio-2-4" name="radio-2-set" class="regular-radio big-radio" /><label for="radio-2-4"></label><br />
            <input type="radio" id="radio-2-5" name="radio-2-set" class="regular-radio big-radio" /><label for="radio-2-5"></label><br />
        </div>
    </div>
</div>
</body>
</html>
复制代码

css

复制代码
body {
    background: #fff;
    padding: 0; margin: 0;
}

#holder {
    width: 100%;
}

#holder > div {
    clear: both;
    padding: 2%;
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    float: left;
    width: 96%;
}

label {
    display: inline;
}

.regular-checkbox {
    display: none;
}

.regular-checkbox + label {
    background-color: #fafafa;
    border: 1px solid #cacece;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
    padding: 9px;
    border-radius: 3px;
    display: inline-block;
    position: relative;
}

.regular-checkbox + label:active, .regular-checkbox:checked + label:active {
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px 1px 3px rgba(0,0,0,0.1);
}

.regular-checkbox:checked + label {
    background-color: #e9ecee;
    border: 1px solid #adb8c0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05), inset 15px 10px -12px rgba(255,255,255,0.1);
    color: #99a1a7;
}

.regular-checkbox:checked + label:after {
    content: '\2714';
    font-size: 14px;
    position: absolute;
    top: 0px;
    left: 3px;
    color: #99a1a7;
}


.big-checkbox + label {
    padding: 18px;
}

.big-checkbox:checked + label:after {
    font-size: 28px;
    left: 6px;
}

.tag {
    font-family: Arial, sans-serif;
    width: 200px;
    position: relative;
    top: 5px;
    font-weight: bold;
    text-transform: uppercase;
    display: block;
    float: left;
}

.radio-1 {
    width: 193px;
}

.button-holder {
    float: left;
}

/* RADIO */

.regular-radio {
    display: none;
}

.regular-radio + label {
    -webkit-appearance: none;
    background-color: #fafafa;
    border: 1px solid #cacece;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
    padding: 9px;
    border-radius: 50px;
    display: inline-block;
    position: relative;
}

.regular-radio:checked + label:after {
    content: ' ';
    width: 12px;
    height: 12px;
    border-radius: 50px;
    position: absolute;
    top: 3px;
    background: #99a1a7;
    box-shadow: inset 0px 0px 10px rgba(0,0,0,0.3);
    text-shadow: 0px;
    left: 3px;
    font-size: 32px;
}

.regular-radio:checked + label {
    background-color: #e9ecee;
    color: #99a1a7;
    border: 1px solid #adb8c0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px -15px 10px -12px rgba(0,0,0,0.05), inset 15px 10px -12px rgba(255,255,255,0.1), inset 0px 0px 10px rgba(0,0,0,0.1);
}

.regular-radio + label:active, .regular-radio:checked + label:active {
    box-shadow: 0 1px 2px rgba(0,0,0,0.05), inset 0px 1px 3px rgba(0,0,0,0.1);
}

.big-radio + label {
    padding: 16px;
}

.big-radio:checked + label:after {
    width: 24px;
    height: 24px;
    left: 4px;
    top: 4px;
}

/* ------- IGNORE */

#header {
    width: 100%;
    margin: 0px auto;
}

#header #center {
    text-align: center;
}

#header h1 span {
    color: #000;
    display: block;
    font-size: 50px;
}

#header p {
    font-family: 'Georgia', serif;
}
#header h1 {
    color: #892dbf;
    font: bold 40px 'Bree Serif', serif;
}

#travel {
    padding: 10px;
    background: rgba(0,0,0,0.6);
    border-bottom: 2px solid rgba(0,0,0,0.2);
    font-variant: normal;
    text-decoration: none;
    margin-bottom: 20px;
}

#travel a {
    font-family: 'Georgia', serif;
    text-decoration: none;
    border-bottom: 1px solid #f9f9f9;
    color: #f9f9f9;
}
复制代码

效果





本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/4995216.html,如需转载请自行联系原作者

相关文章
|
9月前
|
前端开发
HTML与CSS实现网页的超链接及美化
HTML与CSS实现网页的超链接及美化
150 0
HTML与CSS实现网页的超链接及美化
|
10月前
|
前端开发
HTML|利用CSS美化一个html表格
HTML|利用CSS美化一个html表格
294 0
|
9月前
|
前端开发 数据可视化
漏刻有时数据可视化大屏常见问题(12):CSS美化滚动条
漏刻有时数据可视化大屏常见问题(12):CSS美化滚动条
78 0
|
9月前
|
前端开发
HTML利用CSS选择器实现表格美化
HTML利用CSS选择器实现表格美化
94 0
|
11月前
|
前端开发 容器
零基础html5+div+css+js网页开发教程第009期 导航栏css美化
零基础html5+div+css+js网页开发教程第009期 导航栏css美化
146 0
|
前端开发 UED
CSS 美化网页元素【快速掌握知识点】
CSS 美化网页元素【快速掌握知识点】
131 0
CSS 美化网页元素【快速掌握知识点】
|
前端开发 JavaScript
初识CSS,美化HTML
CSS称为:层叠样式表(Cascading style sheets) 美化HTML即给页面种的HTML标签设置样式
|
前端开发
【前端】CSS:页面美化和布局控制和选择器
CSS:页面美化和布局控制和选择器
137 0
|
前端开发 开发者
使用 css 样式表美化组件|学习笔记
快速学习使用 css 样式表美化组件
76 0
使用 css 样式表美化组件|学习笔记
|
前端开发
CSS:页面美化和布局控制
CSS:页面美化和布局控制