checboxのコンテンツを設定する方法は?[複製]
Aug 21 2020
私のAngularアプリで。チェックボックスを使用しています。APIからデータを取得します。チェックボックスの値がtrueの場合。入力値の内容に目盛りが表示されます。空のチェックボックスではなく値がfalseの場合、チェックボックスに「X」を表示するにはどうすればよいですか。案内してください。
HTML
<input class="input" [ngclass]="testForm.get('test').value === false?'unchecked':none " type="checkbox" formControlName="test" readonly>
css
.unchecked {
content: 'X';
color: #fff;
}
回答
1 pc_coder Aug 21 2020 at 17:05
デモこれにはcssを使用できます
<div>
<input class="input" id="checkbox-1"class="checkbox-custom" type="checkbox" readonly>
<label for="checkbox-1" class="checkbox-custom-label">First Choice</label>
</div>
cssとして
.checkbox-custom:checked + .checkbox-custom-label:before {
content: "\f00c";
font-family: 'FontAwesome';
background: blue;
color: #fff;
}
#checkbox-1{
opacity: 0;
position: absolute;
}
.checkbox-custom + .checkbox-custom-label:before, .radio-custom + .radio-custom-label:before {
display: inline-block;
vertical-align: middle;
width: 14px;
height: 14px;
padding: 3px;
text-align: center;
content: "\f00d";
font-family: 'FontAwesome';
background: red;
color:white;
}