Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I tab into CSS3 checkboxes?

Tags:

html

css

checkbox

I've been following tutorial on styling checkboxes using only CSS3 and here's what I came up with:

DEMO:

http://cssdeck.com/labs/jaoe0azx

Checkboxes are styled just fine - but when I tab through form controls -> checkbox is being skipped. Any advice why?

HTML:

<form role="form" id="login_form" data-mode="login">
    <div class="form-group">
       <label for="ue">Username or email:</label>
       <input type="email" class="form-control input-lg" name="ue" id="ue" placeholder="" />
    </div>
    <div class="form-group">
       <label for="password">Password:</label>
       <input type="password" class="form-control input-lg" name="password" id="password" placeholder="" />
    </div>
    <div>
          <input id="rememberme" type="checkbox" name="rememberme" value="1" class="checkbox_1" tabindex="0" />
          <label for="rememberme" class="checkbox_1" tabindex="0">remember me</label>
    </div>
    <div id="auth_area_login_button">
        <button class = "btn btn-lg btn-primary">
            Login
        </button>
    </div>
</form>

CSS:

 @import url('//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css');    

#login_form{padding:20px;}

label.checkbox_1 {
    display: inline-block;
    cursor: pointer;
    position: relative;
    padding-left: 25px;
    margin: 0px;
}

label.checkbox_1:before {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-right: 10px;
    position: absolute;
    left: 0;
    bottom: 1px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 0px;
}
label.checkbox_1:hover:before{border-color:#66afe9;}
input[type=checkbox].checkbox_1 {
    display: none;
}

input[type=checkbox].checkbox_1:checked + label.checkbox_1:before {
    content: "\2713";
    font-size: 15px;
    color: #A0A0A0;
    text-align: center;
    line-height: 15px;
}

EDIT 1:

seems to work in firefox, but not in chrome...

like image 880
Dannyboy Avatar asked Jan 22 '14 13:01

Dannyboy


People also ask

How do I select a checkbox in a tab?

You can use the tab key to bring the cursor to the check-box and hit the space bar on the keyboard to check or uncheck it. Space Bar will do the trick. Once the focus is on the checkbox (by pressing Tab), press the space bar to check/uncheck the check box.

How do I type a checkbox input in CSS?

The solution (in principle)Wrap your checkbox in a label element. This will mean that even when it is hidden, you can still toggle its checked state by clicking anywhere within the label. Hide your checkbox. Add a new element after the checkbox which you will style accordingly.

Can you check a checkbox with CSS?

A checkbox cannot be checked in CSS, unfortunately. It relies on the checked attribute of the input element, and attributes cannot be modified via CSS. Alternatively, you could look into a JavaScript solution, but of course the best way would be to edit the HTML directly.

How do I make checkboxes disabled in CSS?

Use input type="hidden" to store information and process it using JS.


Video Answer


1 Answers

Input must be accessible to receive focus. It works in chrome/chromium if you add following lines.

input[type=checkbox].checkbox_1 {
    opacity: 0;
}
input[type=checkbox].checkbox_1:focus + label.checkbox_1:before {    
    border: 1px solid #66afe9;
}
like image 158
Martin Avatar answered Oct 14 '22 00:10

Martin