HTML / CSS 隐藏复选框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23683136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:48:34  来源:igfitidea点击:

HTML / CSS hide checkbox

htmlcsscheckboxhide

提问by Wistar

How can I hide a checkbox using HTML / CSS?

如何使用 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?

复选框的名称和值不是恒定的。我知道 jquery 有一些方法,但有没有办法用纯 CSS 或 HTML 隐藏它?

回答by codeorelse

Please keep in mind that setting the displayproperty 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:

请记住,将display属性设置为none会使元素无法使用选项卡访问(请参阅:Checkbox tab index not working when set to hidden with custom design)。如果您涉及可访问性,您可以使用:

input[type=checkbox].hidden{
  opacity: 0;
}

回答by Jason

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

这将从显示中隐藏复选框(或任何具有“隐藏”类的 HTML 项目)。该复选框仍然存在于 HTML 中,可以使用 Javascript 或由访问者使用开发人员工具启用/禁用。

回答by SW4

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;">

回答by mohamedrias

you have class hiddenadded to that checkbox.

您已将课程hidden添加到该复选框。

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

or just

要不就

.hidden {
   display:none;
}

回答by HackerManiac

.hidden{
display:none;
}

this will work.

这会起作用。