标签:float png nbsp play int oat 完全 不能 blog
//html <div class="remember-account"> <input type="checkbox"> <span>记住账号</span> </div>
//css .remember-account { display: inline-block; font-size: 18px; color: #fff; float: left; margin-left: 26px; } .remember-account input[type="checkbox"] { -webkit-appearance: none; outline: none; border: none; background-color: transparent; box-sizing: border-box; height: 24px; width: 24px; cursor: pointer; border: 1px solid #fff; box-sizing: border-box; border-radius: 6px; vertical-align: middle; } input[type="checkbox"]:checked { height: 24px; width: 24px; background-image: url(../images/login/pick.png); background-repeat: no-repeat; background-position: 0 0; vertical-align: middle; border: none; } .remember-account span{ display: inline-block; }
//html <div class="remember-account"> <input type="checkbox"> <div class="sub-checkbox"></div> <span>记住账号</span> </div>
//css //增加的样式代码,用/**/注释出来;可对比 .remember-account { position: relative; /*父层*/ display: inline-block; font-size: 18px; color: #fff; float: left; margin-left: 26px; } .remember-account input[type="checkbox"] { position: absolute; /*input,相对定位*/ -webkit-appearance: none; outline: none; border: none; background-color: transparent; box-sizing: border-box; height: 24px; width: 24px; cursor: pointer; border: 1px solid #fff; box-sizing: border-box; border-radius: 6px; vertical-align: middle; opacity: 0; /*透明度为0,隐藏掉input*/ z-index: 2; /* 比input下面的div,z-index:1大,层叠在最上面,点击时候能点击到input */ } /*用div模拟input的样式*/ .sub-checkbox{ display: inline-block; position: absolute; /*input下面的div,相对定位*/ -webkit-appearance: none; outline: none; border: none; background-color: transparent; box-sizing: border-box; height: 24px; width: 24px; cursor: pointer; border: 1px solid #fff; box-sizing: border-box; border-radius: 6px; vertical-align: middle; z-index: 1;/* 比input的z-index:2小,层叠在下面面 */ } /*!!利用伪类的写法+;input选中后,下面的div的样式*/ input[type="checkbox"]:checked + div { height: 24px; width: 24px; background-image: url(../images/login/pick.png); background-repeat: no-repeat; background-position: 0 0; vertical-align: middle; border: none; } .remember-account span{ display: inline-block; margin-left: 30px;/*因为input和它下面的div都相对定位脱离了文本流,所以不给距离,文字会层叠过去*/ }
纯css兼容个浏览器input[type='radio']不能自定义样式
标签:float png nbsp play int oat 完全 不能 blog
原文地址:http://www.cnblogs.com/xiaosuibu/p/6700855.html