很多时候想重新修改css改变浏览器显示 checkbox的 打勾样式效果;
找了很多资料,没有发现眉目;
这次在一个做google浏览器的同事那,看了一下浏览器的源码css ,找到了灵感。这里发出来,也给需要的朋友参考;
button,
input,
select,
textarea,
input[type=text],
input[type=search],
input[type=password],
input[type=email],
input[type=url],
input[type=number],
input[type=radio],
input[type=date],
input[type=time],
input[type=checkbox],
input[type=button],
input[type=submit] {
-webkit-appearance: none;
border-width: 1px;
border-style: solid;
border-color: #333;
border-radius: 2px;
}
input[type=checkbox] {
border-radius: calc( 2 * 0.33);
position: relative;
width: 16px;
height: 16px;
min-width: 16px;
min-height: 16px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1) inset;
background-color: #f1f1f1;
margin: unset;
}
input[type=radio]:focus:before,
input[type=checkbox]:focus:before,
input[type=radio]:focus:after,
input[type=checkbox]:focus:after,
input[type=radio]:active:focus:before,
input[type=checkbox]:active:focus:before,
input[type=radio]:active:focus:after,
input[type=checkbox]:active:focus:after {
background-color:#222;
}
button:focus:not([tabindex='-1']),
input:focus:not([tabindex='-1']),
select:focus:not([tabindex='-1']),
textarea:focus:not([tabindex='-1']),
input[type=text]:focus:not([tabindex='-1']),
input[type=search]:focus:not([tabindex='-1']),
input[type=password]:focus:not([tabindex='-1']),
input[type=email]:focus:not([tabindex='-1']),
input[type=url]:focus:not([tabindex='-1']),
input[type=number]:focus:not([tabindex='-1']),
input[type=radio]:focus:not([tabindex='-1']),
input[type=date]:focus:not([tabindex='-1']),
input[type=time]:focus:not([tabindex='-1']),
input[type=checkbox]:focus:not([tabindex='-1']),
input[type=button]:focus:not([tabindex='-1']),
input[type=submit]:focus:not([tabindex='-1']) {
border-color: #222;
box-shadow: 0 0 0 1px #222;
}
input[type=checkbox]:before,
input[type=checkbox]:after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #bf0000;
transform-origin: 0 0;
transition: transform 0ms linear 0ms;
}
input[type=checkbox]:before {
transform: rotate(-45deg) translateY(45%) translateX(-30%) scaleX(0.15) scaleY(0);
}
input[type=checkbox]:after {
transform: rotate(225deg) translateY(-30%) translateX(-95%) scaleX(0.15) scaleY(0);
transition-delay: 0ms;
}
input[type=checkbox]:indeterminate:before {
transform: rotate(0) translateY(37.5%) translateX(10%) scaleX(0.8) scaleY(0.25);
transition-duration: 0ms;
}
input[type=checkbox]:checked:before {
transform: rotate(-45deg) translateY(45%) translateX(-30%) scaleX(0.15) scaleY(0.4);
transition-duration:0ms;
}
input[type=checkbox]:checked:after {
transform: rotate(225deg) translateY(-30%) translateX(-95%) scaleX(0.15) scaleY(0.7);
transition-duration: 0ms;
transition-delay: 0ms;
}
上面的css代码,并不多。但是都是相当有分量,每一句都能起到效果;
scaleX(0.15) scaleY(0.7);
这一段是改变打勾的 粗细 ,和角度。;
input[type=checkbox]:before
构成勾勾 的前半部分;控制角度和粗细
input[type=checkbox]:after
这 一段 构成勾勾的后半部分。控制角度和粗细