Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css only checkbox (with content attribute)

Tags:

html

css

checkbox

how can I make a custom checkbox with css only (no JS no JQ) with content:"on" when checked and content:"off" when uncheked.

Thanks.

reedit

OK, after LOT of copy/paste/delete, it work now.

Thank.

like image 618
JustTrying Avatar asked Dec 08 '22 19:12

JustTrying


2 Answers

input[type=checkbox] {
    position: relative;
    visibility: hidden;
    cursor: pointer;
}

input[type=checkbox]:after {
    display: block;
    content: "OFF";
    position: absolute;
    top: 0;
    right: -30px;
    visibility: visible;
    height: 30px;
    line-height: 30px;
    width: 50px;
    text-align: center;
    border-radius: 4px;
    background: #d00;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

input[type=checkbox]:checked:after {
    content: "ON";
    background: #0a0;
}
<input type="checkbox" />
like image 133
Zoltan Toth Avatar answered Jan 02 '23 01:01

Zoltan Toth


It is possible. Check out these blog posts by Ryan Seddon. He explain how you can play with checkbox and CSS

http://www.thecssninja.com/css/custom-inputs-using-css

http://www.thecssninja.com/css/futurebox3

http://www.thecssninja.com/css/css-tree-menu

like image 21
Zendy Avatar answered Jan 02 '23 02:01

Zendy