Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css to replace an image

Tags:

css

skinning

I am familiar with CSS techniques to replace text with an image. For example, here are 9 of them: http://css-tricks.com/nine-techniques-for-css-image-replacement/

Are there any techniques for replacing images? Is there anyway to set the background of an image to an image and then hide or move the foreground of the image (the image src element).

I am trying to write a skin for a site that has an image that I want to replace. Thanks.

From how I understand it he's trying to do this in pure CSS, with no changes to HTML or JavaScript.

That is correct. I am adding a new stylesheet to an existing page. Let say I can not modify HTML or utilize javascript.

like image 923
MikeNereson Avatar asked Jul 03 '09 19:07

MikeNereson


People also ask

How do I replace one image with another in CSS?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.

How do I replace text with an image in CSS?

To replace the text with a logo image, use a negative text indent value (it has to be a pretty high value, like the one below) and insert the image using background: url(). Make sure you define the width and height as well, or the image won't render.

What is image replacement technique?

CSS image replacement is a technique of replacing a text element (usually a header tag like an <h1> ) with an image (often a logo). It has its origins in the time before web fonts and SVG.


1 Answers

After a little bit of tinkering, I figured it out!

img.someclass {
  background: url("NEW IMAGE URL") top right;
  height: 0;
  width: 0;
  padding: 200px 550px 0 0; /* Insert actual image size (height width 0 0) */
}

This will make the height and width of the actual image 0, but will expand the box to fill the size of the image with padding. The only downside to this is it won't look perfect in older versions of Internet Explorer.

like image 133
Sasha Chedygov Avatar answered Sep 18 '22 17:09

Sasha Chedygov