Let's say I've got this code
<table>
<tr>
<td><input id="foo" type="text"></td>
<td><label for="foo">This is foo</label></td>
</tr>
</table>
This will hide the input:
#foo { display: none;} /* or hidden could work too, i guesss */
How do I hide the label?
Hiding the label with display: none; is bad for web accesibility and you shouldn't do it. Try visibility: hidden; instead. yep, why I added a label I didn't want to see in the first place. display: block; height: 0; visibility: hidden; .
Completely hiding elements can be done in 3 ways: via the CSS property display , e.g. display: none; via the CSS property visibility , e.g. visibility: hidden; via the HTML5 attribute hidden , e.g. <span hidden>
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <label> element is not visible, but it maintains its position on the page.
The visibility CSS property shows or hides an element without changing the layout of a document.
If you give the label an ID, like this:
<label for="foo" id="foo_label">
Then this would work:
#foo_label { display: none;}
Your other options aren't really cross-browser friendly, unless javascript is an option. The CSS3 selector, not as widely supported looks like this:
[for="foo"] { display: none;}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With