簡體   English   中英

基於 CSS 的復選框樣式

[英]Checkbox Styling based on CSS

我有一個復選框,應如下所示,

在此處輸入圖片說明

如果未選中,則應如下所示,

在此處輸入圖片說明

我有以下 css

input[type="checkbox"]:checked + label::after {
  content: '';
  position: absolute;
  width: 11px;
  height: 6px;
  background: rgba(0,0,0,0);
  top: 10px;
  left: 24px;
  border: 1px solid white;
  border-top: none;
  border-right: none;
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  transform: rotate(-45deg);
}

input[type="checkbox"] {
  line-height: 2.1ex;
}

input[type="radio"],
input[type="checkbox"] {
   position: absolute;
   left: -999em;
}

input[type="checkbox"] + label {
   position: relative;
   overflow: hidden;
   cursor: pointer;
}

input[type="checkbox"] + label::before {
  content: "";
  display: inline-block;
  vertical-align: -25%;
  height: 20px;
  width: 20px;
  background-color: #1BAAD3;
  border-radius: 4px;
  margin-right: 8px;
}

當我取消選中復選框時,這是我可以看到的

在此處輸入圖片說明

我正在使用 angular-js 來處理選擇/取消選擇的事件

HTML

<div class="form-check">
   <input type="checkbox" ng-if="testKits" ng-model="testKits" class="form-check-input" id="testKits">
   <label class="form-check-label form-label-text source-sans-pro" for="testKits">{{'Testkits' | translate}}</label>
</div>

請參閱下面的代碼片段,它可能對您有用:

 input[type="checkbox"]:checked + label::after { content: ''; position: absolute; width: 11px; height: 6px; background: rgba(0,0,0,0); top: 0px; left: 6px; border: 1px solid white; border-top: none; border-right: none; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -o-transform: rotate(-45deg); -ms-transform: rotate(-45deg); transform: rotate(-45deg); } input[type="checkbox"] { line-height: 2.1ex; } input[type="radio"], input[type="checkbox"] { position: absolute; left: -999em; } input[type="checkbox"] + label { position: relative; overflow: hidden; cursor: pointer; } input[type="checkbox"] + label::before { content: ""; display: inline-block; vertical-align: -25%; height: 20px; width: 20px; background-color: #fff; border-radius: 4px; margin-right: 8px; border: 2px solid #ddd; } input[type="checkbox"]:checked + label::before { background-color: #1BAAD3; border: 2px solid #1BAAD3; }
 <div class="form-check"> <input type="checkbox" class="form-check-input" id="testKits"> <label class="form-check-label form-label-text source-sans-pro" for="testKits">abc</label> </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM