Arnis Lapsa
Arnis Lapsa

Reputation: 47567

How to hide text using CSS?

How to make foo invisible using CSS (CSS3 if needed) while keeping bar and fizz visible?

<table>
  <tr>
    <td>
      <textarea>bar</textarea>
      <input type='button' title='fizz' />
      foo
    </td>
  </tr>
</tbody>

Making foo in the same color as background is acceptable, but the trick is - background is an image, hence - foo must be transparent instead of solid color.

JavaScript isn't an option either.

Changing HTML is not an option either.

Any ideas?

Upvotes: 4

Views: 13414

Answers (7)

ScottS
ScottS

Reputation: 72261

This worked fine in IE8 and Firefox (IE7 left little dots for words, which I guess if you set the font-color to something that blends with the background image, it might do fine. Note that this does not affect either the text-area or the input for any text in them.

td {font-size: 0;}

ADDED ON EDIT

WOW I mean, really! This worked on IE7-8, Firefox, and Safari

td {visibility: hidden}
td textarea,
td input {visibility: visible;}

As a side note, I tested this with elements wrapped in div rather than a table, I even did a div in a div and the inner div shows while other content is hidden.

Apparently, the visibility property acts on the element, and (unlike opacity) propagates to the child elements by inheritance, so that if one explicitly sets a child element visibility it no longer inherits the hidden but uses its own setting of visible and the fact that the wrapper is hidden does not matter.

Upvotes: 9

Thom Smith
Thom Smith

Reputation: 14086

EDIT: Scott's is better. Use his.

I don't think a proper solution is going to be pretty.

td {
    position: relative;
    left: 9001px;
}

textarea {
    position: relative;
    right: 9001px;
}

Upvotes: 3

robertc
robertc

Reputation: 75707

If you don't have to support IE then setting the text to transparent is easy:

table {
    background-color: cyan;
}
td {
    color: rgba(255,255,255,0);
}
td textarea, td input {
    color: #000;
}

Upvotes: 1

aronchick
aronchick

Reputation: 7128

How about the reverse of Amber's suggestion -

Set overflow to overflow: hidden on the TD, fix the size where it is right now and add a huge padding-bottom on the textarea or button.

Upvotes: 0

Marc B
Marc B

Reputation: 360572

whoops... should've read the OP a bit more closely. Guess the following won't work after all, since changing the html isn't an option.

Set a css class on the container you want to hide (the textarea?):

...
   <textarea class="hideme">bar</textarea>
...

and the following css:

.hideme {
   display: hidden;
}

'hidden' makes the element disappear (it's literally not displayed), but still is still accounted for in the document flow and takes up the space it normally would. If you want it to literally be gone and not have any effect on the document, then use display: none.

Upvotes: 0

Amber
Amber

Reputation: 526523

Set the size of the td to be the same as the size of the textarea (via CSS width and height), then set overflow: hidden on the TD so that the text you want to hide is outside the bounding box?

Upvotes: 0

Ahmed Aman
Ahmed Aman

Reputation: 2393

You need to put it inside a container like a div then hide the container ..

Upvotes: 0

Related Questions