4

I need to hide the text inside a H1 tag. But not the image. Problem is that i only can change the css and not the html

<h1>
<img src="img/headerimg.png" width="900" height="125"/>
Header 1 text
</h1>

Is there a way to only hide the "Header 1 text" with only css? I'm doing this for big client and they gave me only acces to the css file.

user1386906
  • 1,161
  • 6
  • 26
  • 53

7 Answers7

8

Give a 0px font size

​h1{ font-size:0px }​

Edit: Working sample

hkutluay
  • 6,794
  • 2
  • 33
  • 53
  • In Opera Browser the text is still visible, very small but still visible. – wzazza Oct 13 '12 at 13:36
  • 1
    ​h1{ font-size:0px; color: rgba(0,0,0,0) }​ This will also make the font invisibile. The element is still in the DOM and has an effect on other surrounding images. The only good solution is to change HTML. – Hendrik Oct 13 '12 at 15:43
5

Set the image as background of the <h1>, add CSS properties to the <h1> to make it the size of the image and use a negative text-indent on the headline to remove the text. That would be the usual and ideal way to do it if you had access to the html too.

Since you only have access to the CSS, you can use this:

h1 {
    font-size: 0.1px; /* 0 gets disregarded by Internet Explorer, 0.1 gets interpreted right by every browser */
}

Fiddle: http://jsfiddle.net/VGgnD/

Markus Unterwaditzer
  • 7,992
  • 32
  • 60
3

You can do this way using CSS:

<h1>
    <img src="img/headerimg.png" width="900" height="125"/>
    Header 1 text
</h1>

CSS:

h1 {
    width: 900px;
    height: 125px;
    background: url("img/headerimg.png") no-repeat center center;
    text-indent: -99em;
}

If you have access only to CSS, please display: none; the img:

h1 img {display: none;}

Working Fiddle: http://jsfiddle.net/sJ8JD/

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
1

Well the only thing that comes to my mind is this:

<h1 style="color: transparent; font-size: 0px; text-indent: -99em;">
<img src="http://pokit.org/get/img/18d5148ef77ef2a2d5d8193c1c8789e8.jpg" width="900" height="125"/>
Header 1 text
</h1>

Working example:

http://jsfiddle.net/VRQVs/2/

0

set font-size: 1px !important; and set background color as text color

haynar
  • 5,961
  • 7
  • 33
  • 53
0

You can try position:absolute; so the text won't be visible, it will be positioned outside the page. -5000px

h1 {
  margin-top:-5000px;
  position:absolute;
}
h1 img {
  position:absolute;
  margin-top:5000px;
}

Example

wzazza
  • 803
  • 2
  • 11
  • 19
0

It could be as simple as setting the font-size to 0px

h1 {
   font-size: 0.1px;
}

http://jsfiddle.net/m5V2A/

thescientist
  • 2,906
  • 1
  • 20
  • 15