css 黑科技

单选框和复选框的样式

使用unicode编码字符和before after属性,模拟选中和非选中状态
<!-- html -->
<input type="checkbox" id="check" name="check" />
<label for="check">Checkbox</label><br/>
<input type="radio" id='aaa' name="radio" valuse='aaa'/>
<label for="aaa">aaa我是</label><br/>
<input type="radio" id='bbb' name="radio" valuse='bbb'/>
<label for="bbb">bbb</label>


<!-- css -->
input[type=checkbox], 
  input[type=radio] {display: none;}
label{display: flex; align-items: center; font-size: 16px;} 
input[type=checkbox]:checked + label:before, 
  input[type=radio]:checked + label:before {color: #000;}
/*checkbox */
input[type=checkbox] + label:before { 
    display:inline-block;       
    margin: 0 5px 0 0;
    height: 12px;
    width: 12px;
    border: 1px solid #000;
    content: "\2714";
    text-align: center;
    color: transparent;
    font-size: 12px;    
    line-height: 12px;
    transition: color ease .3s;         
}

/*radio*/
input[type=radio] + label:before {  
    display: inline-block;
    border-radius: 50%;
    margin: 0 5px 0 0;
    height: 14px;
    width: 14px;        
    border: 1px solid #000;
    content: "\26AB";
    color: transparent; 
    font-size: 12px;    
    transition: font-size ease .3s;
    text-align: center;
    line-height: 14px;
    transition: color ease .3s; 
}

这里写图片描述


高级CSS计数器

<!-- css -->
input[type=checkbox] {opacity: 0; position: absolute;}
label{display: flex; align-items: center; font-size: 16px;} 
input[type=checkbox] + label:before { 
    display:inline-block;       
    margin: 0 5px 0 0;
    height: 12px;
    width: 12px;
    border: 1px solid #000;
    content: "\2714";
    text-align: center;
    color: transparent;
    font-size: 12px;    
    line-height: 12px;
    transition: color ease .3s;         
}
input[type=checkbox]:checked + label:before {color: #f00;}

.languages {
    counter-reset: characters;
}
input[type=checkbox]:checked {  
    counter-increment: characters;
}
.total:after {
    content: counter(characters);
} 
<!-- html -->
<div class="languages">  
    <input id="c" type="checkbox"><label for="c">C</label>
    <input id="C++" type="checkbox"><label for="C++">C++</label>
    <input id="C#" type="checkbox"><label for="C#">C#</label>
    <input id="Java" type="checkbox"><label for="Java">Java</label>
    <input id="JavaScript" type="checkbox"><label for="JavaScript">JavaScript</label>
    <input id="PHP" type="checkbox"><label for="PHP">PHP</label>
    <input id="Python" type="checkbox"><label for="Python">Python</label>
    <input id="Ruby" type="checkbox"><label for="Ruby">Ruby</label>
</div>  
<p class="total">  
    Total selected:
</p> 

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值