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?
To hide text from a screen reader and hide it visually use the hidden attribute. You can also use CSS to set display: none or visibility: hidden to hide an element from screen readers and visually.
visibility:hidden , color:transparent and text-indent will do this. the font-size:0 option will work better I think. It should be remembered that some of these solutions will only hide the text. They will still leave a space for it on the screen.
Try setting display:none to hide and set display:block to show. not all items should be display: block , some will have to be set to display: inline (such as <span> or <a> or <img> DOM elements). @pranay the question says to hide them not to remove them from the DOM.
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>
.closelink {
font-size: 0px;
}
.close-link a {
font-size: 12px;
}
Try
#closelink {
position: relative;
left: -9999px;
}
#closelink a {
position: relative;
left: 9999px;
}
<div id="closelink">
<a href="">Close</a> Click to close
</div>
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