0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

3段階のチェックボックス

Posted at

はじめに

WEBシステムで、3段階のチェックボックスを作ろうと思います。

image.png

調べてみる

どこを調べても、javascriptでindeterminateをtrueにすれば良いという情報ばかりでした。

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <input type="checkbox" />
    <input type="checkbox" checked/>
    <input type="checkbox" id="chkIndeterminate"/>
</body>
<script type="text/javascript">
    document.getElementById('chkIndeterminate').indeterminate = true;
</script>
</html>

CSSだけで何とかしたい…

CSSだけで作ってみる

See the Pen Untitled by masayasu_t (@cjlsrdxi-the-builder) on CodePen.

チェックボックスに見えますが、正体はラジオボタンです。

非表示にしている要素を表示すると、このようになっています。
image.png

チェックなし状態と左、チェックあり状態と真ん中、3ステータス状態と右のラジオボタンがリンクしています。
image.png

そして、右のラジオボタンにチェックが入っているときは、チェックなし状態を表示(チェックあり状態と3ステータス状態は非表示)
image.png

左のラジオボタンにチェックが入っているときは、チェックあり状態を表示(チェックなし状態と3ステータス状態は非表示)
image.png

真ん中のラジオボタンにチェックが入っているときは、3ステータス状態を表示(チェックなし状態とチェックあり状態は非表示)
image.png

おわりに

このやり方を用いると4段階以上のチェックボックス?が作れます。
デザインのバリエーションを増やすために作ってみましたが、使い勝手は微妙です

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?