Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can CSS alter an input element's SRC attribute?

Tags:

css

Is it possible, via CSS to remove or change the src reference in the markup below?

The easy thing to do would be to change the markup, however, this code is in the wild and I need to deal with it as it is, so I'm trying to remove the image and use a background image instead.

<input type="image" src="wp-content/uploads/image.png" name="submit" class="submit" value="Submit" /> 
like image 649
Scott B Avatar asked Sep 26 '11 03:09

Scott B


People also ask

Can CSS set src?

No you can't set the image src attribute via CSS. The closest you can get is, as you say, background or background-image .

What does the src attribute do?

Definition and Usage The src attribute specifies the location (URL) of the external resource.

Can you change img src?

Change Img src If you'd like to replace an image on your website, then you can simply change the image file path or URL in its source attribute. You can change this attribute at any time. It's important to note that the new image inherits the height and width attributes of the original image.


2 Answers

You can experiment with setting height and width to 0, add a padding and set the background image. You will have to make it display: block or display: inline-block for the height to take effect.

Here's an example - http://jsfiddle.net/zBgHd/1/

like image 131
Chetan S Avatar answered Sep 24 '22 07:09

Chetan S


Actually, I just figured it out.

.submit {width:0;height:28px;background:url(go.png) no-repeat; padding-left:28px;}

My replacement image is 28x28. By specifying a left padding equal to that, and a width of zero, it effectively pushes the image off the viewable area of the box, leaving the background image to show.

like image 33
Scott B Avatar answered Sep 20 '22 07:09

Scott B