Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide element label by element id in CSS?

Tags:

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?

like image 248
Stoob Avatar asked Apr 22 '10 21:04

Stoob


People also ask

How do you hide a label in CSS?

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

How do I completely hide an element in CSS?

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>

How do you hide labels in HTML?

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.

Which CSS property is used to hide an element?

The visibility CSS property shows or hides an element without changing the layout of a document.


1 Answers

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;}
like image 73
Nick Craver Avatar answered Sep 22 '22 13:09

Nick Craver