LoginSignup
1
0

More than 3 years have passed since last update.

カスタムチェックボックスの作り方

Posted at
  1. もともとあるinputを隠す
input {
position:absolute;
height: 0px;
}
  1. :checkedにさせるコンテンツの追加
input:checked ~ label::before {
content:"[x]";
}

~は兄弟

サンプル

<style>
input[type=checkbox] {
position: absolute;
height: 0px;
}
input:not(:checked) ~ label::before {
content: "[-]";
}
input:checked ~ label::before {
content: "[x]";
}
</style>
<input type="checkbox" id="aaa-field"/>
<label for="aaa-field">aaa</label>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0