468,765 Members | 1,729 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

Is there a way to set the image for an <input type="image"> in CSS?

Hello,

If I have the following HTML...

<input type="image" src="fred.gif">

.... is there a way to specify the image in CSS rather than in the HTML?

TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Jan 19 '06 #1
2 2419
Alan Silver wrote:
If I have the following HTML...

<input type="image" src="fred.gif">
Then you should fix it to use <input type="submit" value="...">.
... is there a way to specify the image in CSS rather than in the HTML?


Yes and no. You could e.g. use a dummy image (transparent single-pixel
image) as fred.gif and use CSS to set a background image for the
element. But don't. To begin with, it would fail whenever CSS is turned
off or your author style sheet is ignored, as well as when browsing in
no-images mode.

The relevant thing is that you should not use image submit buttons in
the first place. For reasons, see
http://www.cs.tut.fi/~jkorpela/forms/imagebutton.html
Jan 19 '06 #2
>> If I have the following HTML...
<input type="image" src="fred.gif">


Then you should fix it to use <input type="submit" value="...">.


It was air code, purely intended to show the tag I meant. I only use
full, valid HTML in real documents ;-)
... is there a way to specify the image in CSS rather than in the HTML?


Yes and no. You could e.g. use a dummy image (transparent single-pixel
image) as fred.gif and use CSS to set a background image for the
element. But don't. To begin with, it would fail whenever CSS is turned
off or your author style sheet is ignored, as well as when browsing in
no-images mode.

The relevant thing is that you should not use image submit buttons in
the first place. For reasons, see
http://www.cs.tut.fi/~jkorpela/forms/imagebutton.html


OK, I'm convinced!!

Don't you wish it was always that easy?

Thanks for the reply.

--
Alan Silver
(anything added below this line is nothing to do with me)
Jan 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mikko Rantalainen | last post: by
3 posts views Thread by =?Utf-8?B?V2lsbA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.