css - 如何在 CSS 中通过元素 id 隐藏元素标签?

标签 css input label

假设我有这段代码

<table>
    <tr>
        <td><input id="foo" type="text"></td>
        <td><label for="foo">This is foo</label></td>
    </tr>
</table>

这将隐藏输入:

#foo { display: none;}  /* or hidden could work too, i guesss */

如何隐藏标签?

最佳答案

如果您给标签一个 ID,如下所示:

<label for="foo" id="foo_label">

那么这会起作用:

#foo_label { display: none;}

您的其他选项并不是真正的跨浏览器友好,除非 javascript 是一个选项。没有得到广泛支持的 CSS3 选择器看起来像这样:

[for="foo"] { display: none;}

关于css - 如何在 CSS 中通过元素 id 隐藏元素标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2694683/

相关文章:

php - 我怎样才能让这个得到 echo

javascript - AngularJS : ng-repeat for plain text

android - GameLoop 检查输入 (Android/GlSurfaceView)

Python tkinter - 动态更改标签字体颜色

css - 框架集不工作

html - 尝试将图像导航链接与导航中的其余文本链接均匀间隔开

html - Twitter Bootstrap 的底部填充/边距问题

javascript - 从输入中获取值并在 div 中显示

java - 有没有办法转到方法的特定部分,而不是方法的开始?

html - <label>的语义也用出了一个<form>?