1
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?

More than 5 years have passed since last update.

htmlとcssだけで切り替え式のスイッチを作る方法

Last updated at Posted at 2019-06-19

html

<label class='switch'>
       <input class='switch-checkbox' type='checkbox'>
       <div class='switch-unchecked'>OFF</div>
       <div class='switch-checked'>ON</div>
</label>

SCSSS

.switch {
    display: inline-flex;

    width: 200px;
    background-color: #FFFFFF;
    border: solid 1px #000000;
    user-select: none;
    -webkit-touch-callout: none;

    .switch-checkbox {
        display: none;
    }
    .switch-checked,.switch-unchecked{
        flex-grow: 1;
        display: inline-flex;
        justify-content: center;
        align-items: center;
    }
    .switch-checkbox:checked~.switch-checked,
    .switch-checkbox:not(:checked)~.switch-unchecked {
        background-color: red;
    }
}
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?