2017-11-17 115 views
0

我有一個複選框設置。我試圖讓它顯示一個Font Awesome圖標。即,選中時爲fa-link,未選中時爲空。複選框 - 用fa-link替換複選標記

下面是代碼:

input[type="checkbox"] { 
 
    -webkit-appearance: initial; 
 
    appearance: initial; 
 
    outline: 1px solid #A9A9A9; 
 
    width: 25px; 
 
    height: 25px; 
 
    background: #FFFFFF; 
 
    position: relative; 
 
} 
 

 
input[type="checkbox"]:checked { 
 
    background: #0073C0; 
 
} 
 

 
input[type="checkbox"]:checked:after { 
 
    content: "\2713"; 
 
    color: #fff; 
 
    position: absolute; 
 
    left: 50%; 
 
    top: 50%; 
 
    -webkit-transform: translate(-50%, -50%); 
 
    -moz-transform: translate(-50%, -50%); 
 
    -ms-transform: translate(-50%, -50%); 
 
    transform: translate(-50%, -50%); 
 
    outline: 1px solid #A9A9A9; 
 
}
<input id="box1" type="checkbox" />

它應該是這樣的:

我似乎無法想出解決辦法。

+0

如果你想渲染你需要設置'FONT-FAMILY一個字體真棒圖標:「FontAwesome」;',你在''的設置content'爲Unicode字符:after'風格 – zgood

回答

2

要使用這樣的Font Awesome圖標,您需要將字體系列設置爲FontAwesome,並在其中設置內容的Unicode字符。此外,請確保您使用的是正確的Unicode字符(鏈接圖標及其\f0c1

像這樣:

input[type="checkbox"]:checked:after { 
    font-family: 'FontAwesome'; 
    content: "\f0c1"; 
    .... 
} 

的演示中看到這個fiddle

+0

即使世界白色虛線鏈接周圍的虛線框。我怎樣才能刪除這個?謝謝 – piddler

+0

那是因爲你的風格是'outline:1px solid#A9A9A9;',只需將其刪除 – zgood