csstextnode

Hide text node in element, but not children


I'm having a little trouble with CSS and can't seem to find a solution. I have this HTML

<div id="closelink">
  <a href="">Close</a>
  Click to close
</div>

Now I want to hide the text «Click to close» only, without hiding neither the div, nor the link within it.

Can this be done?


Solution

  • The visibility attribute can be overriden on children elements, so you are able to do this:

    #closelink {
      visibility: collapse;
    }
    
    #closelink a {
      visibility: visible;
    }
    <div id="closelink">
      <a href="">Close</a> Click to close
    </div>