Browse > Home / CSS, Web Design / Better Image replacement technique

Better Image replacement technique

January 2, 2008

It fixes bug that makes the solution unusable if images are switched off in a browser:

The HTML code:

<h1 class=”ReplaceWithImage” id=”ImageHeader”>Replaced Text<span></span></h1>

The CSS code: 

.ReplaceWithImage{
  position:relative;
  margin:0px; padding:0px;
  /* hide overflow:hidden from IE5/Mac */
  /* \*/
  overflow: hidden;
  /* */
}
.ReplaceWithImage span{
  display:block;
  position:absolute;
  top:0px;
  left:0px;
  z-index:1; /*for Opera 5 and 6*/
}
#ImageHeader, #ImageHeader span{
  height:100px;
  width:300px;
  background-image: url(image.jpg);
}

Works in:

  • Opera 5 and up
  • IE 7/win
  • IE 6/win
  • IE 5.5/win
  • IE 5/win
  • Mozilla Firebird
  • Mozilla 1.2
  • Konqueror 3.1.2
  • Safari
  • Camino
  • Omniweb
  • IE5.2/Mac OS X

Written by Olegs Marhelis · Filed Under CSS, Web Design 

Comments

Got something to say?