6

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" /> 
1
  • I don't think so.. How about javascript? Commented Sep 26, 2011 at 3:22

4 Answers 4

9

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/

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

Although that is specifically about the img src attribute, it still holds true for input src. This question pretty much answers it for you - How to change an input button image using CSS? Another related question: Define an <img>'s src attribute in CSS

Comments

0

No, to answer your question. Not in any version of any browser (AFAIK).

Any solution will involve a workaround. I'm testing out one right now, where you use a :before rule to create a background image on top of it.

Update... Well, for what it's worth, :before is not respected on input elements, whereas @Chetan's fiddle does work when I change the img tag to input. So, kudos.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.