当前位置:首页 > Web开发 > 正文

css改变checkbox的背景

2024-03-31 Web开发

checkbox默认不支持修改背景颜色,利用伪类元素实现,,基本原理是利用after/ before插入新的元素。然后利用新元素的背景颜色或背景图片覆盖掉原来的样式。

原始样子

要实现的样子

<input type="checkbox" />

input[type=checkbox] { cursor: pointer; position: relative; } input[type=checkbox]:after { position: absolute; width: 10px; height: 10px; content: " "; background-color: rgb(200,237,255); visibility: visible; border-top: 1px solid #ccc; border-left: 1px solid #ccc; } input[type=checkbox]:checked:after { content: "?"; position: absolute; line-height: 11px; left: 0; top: 0; }

css改变checkbox的背景

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/41641.html