I have a tag in my html like this:
<h1>My Website Title Here</h1>
Using css I want to replace the text with my actual logo. I've got the logo there no problem via resizing the tag and putting a background image in via css. However, I can't figure out how to get rid of the text. I've seen it done before basically by pushing the text off the screen. The problem is I can't remember where I saw it.
Use display:none , and the text is gone.
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.
This is one way:
h1 { text-indent: -9999px; /* sends the text off-screen */ background-image: url(/the_img.png); /* shows image */ height: 100px; /* be sure to set height & width */ width: 600px; white-space: nowrap; /* because only the first line is indented */ } h1 a { outline: none; /* prevents dotted line when link is active */ }
Here is another way to hide the text while avoiding the huge 9999 pixel box that the browser will create:
h1 { background-image: url(/the_img.png); /* shows image */ height: 100px; /* be sure to set height & width */ width: 600px; /* Hide the text. */ text-indent: 100%; white-space: nowrap; overflow: hidden; }
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