Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide text using css

Tags:

css

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.

like image 943
Micah Avatar asked Jan 23 '09 01:01

Micah


People also ask

How do you remove text in CSS?

Use display:none , and the text is gone.

How do you hide text in an element?

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.


1 Answers

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; } 
like image 82
nicholaides Avatar answered Oct 13 '22 08:10

nicholaides