[英]Set custom image to checkbox without mandatory label
我有一個項目,其中有時復選框沒有標簽。 對於復選框,我發現設置自定義圖像的唯一方法是設置圖像label:before
對應label
,其具有for
與價值id
復選框。
是否有任何CSS方法(至少是hacky)將自定義圖像設置為復選框而不更改標記? input[type="checkbox"]:before
僅適用於Chrome。
我發現除了IE桌面版(甚至在Edge中)之外,其他所有地方都可以使用的唯一方法是通過設置CSS appearance
:
input[type="checkbox"] { width: 16px; height: 16px; -webkit-appearance: none; -moz-appearance: none; appearance: none; background-color: red; } input[type="checkbox"]:checked { background-color: green; }
<input type="checkbox" />
也許如果您將容器添加到這樣的復選框中
<div>
<input type="checkbox">
</div>
接着
div{
position: relative;
/* Your custom style */
}
input{
position: absolute;
height: 100%;
width: 100%;
left: 0;
top: 0;
opacity: 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.