HTML / CSS hide checkbox

2019-04-13 21:55发布

How can I hide a checkbox using HTML / CSS?

Let's say I have

<table>
    <thead>
        <th>
         Col A
        </th>
         <th>
         Col B
         </th>
    </thead>
    <tbody>
        <tr>
            <td> <input type="checkbox" class="hidden"> Some stuff </td>
        </tr>
         <tr>
            <td> Some Other stuff </td>
        </tr>
    </tbody>
</table>

The name and the values of the checkbox are not constant. I know there's some way with jquery but is there a way to hide it with pure CSS or HTML?

5条回答
混吃等死
2楼-- · 2019-04-13 22:20
.hidden{
display:none;
}

this will work.

查看更多
我命由我不由天
3楼-- · 2019-04-13 22:25

Simple enough!

input[type=checkbox].hidden{
   display:none;
}

Or if you want to be crazy and use inline styles (best to avoid):

<input type="checkbox" class="hidden" name="V" value="B" style="display:none;">
查看更多
疯言疯语
4楼-- · 2019-04-13 22:32
.hidden {
    display: none;
}

This will hide the checkbox (or any HTML item with the class of "hidden") from display. The checkbox still exists in HTML and can be enabled/disabled with Javascript or by visitors with developer tools.

查看更多
干净又极端
5楼-- · 2019-04-13 22:42

you have class hidden added to that checkbox.

input[type=checkbox].hidden {
   display:none;
}

or just

.hidden {
   display:none;
}
查看更多
做个烂人
6楼-- · 2019-04-13 22:45

Please keep in mind that setting the display property to none, makes the element inaccessible using tabs (see: Checkbox tab index not working when set to hidden with custom design). If you case about accessibility, you can use:

input[type=checkbox].hidden{
  opacity: 0;
}
查看更多
登录 后发表回答