0

I would like to make a button (clickable element) without text but with an image.
I want the image to be defined in the css.

If I use Image element, the image cannot be defined in the css.
Using div looks like irrelevant.

something like:

<elem></elem>

elem {
    backround-image:url(img.jpg);
}

How can I do this? What is elem?

4
  • Unless you want to add javascript to your page, elem can only be an a element if you want it to act like a link. Commented Jun 4, 2011 at 14:25
  • @Niklas: I don't see any connection between javascript and a element. Commented Jun 4, 2011 at 14:30
  • 1
    Well any element on a page can be clicked, but if you expect it to actually do something, it will have to be a link or submit button, unless you attach click handlers on it. Commented Jun 4, 2011 at 14:32
  • @Niklas: I don't care attach event handlers. This is only html and css question. I am looking for the best approach to do so. Commented Jun 4, 2011 at 14:37

2 Answers 2

2

You can use a button element by reseting it's defaults CSS, Or use DIV.
Button is more semantic.
Obviously you will still need to add an event handler to the onclick event for it to do something.

Example:

<style>
.myburron{
   background-image: url('../myimage.jpeg');
   width: Xpx;
   height:Ypx;
   display: [not sure, think inline-block is best];
   border-style: none;
   background-color: none;
}
</style>

...
...
...
<button class="myburron"> </button>
Sign up to request clarification or add additional context in comments.

2 Comments

what do you meen by "button element"? I need the html to be valid. If the button element requires imageSrc attribute it won't fit.
No- most html elements can have a background image
2

HTML:

<input type="button" name="btn" id="btn">

CSS:

#btn{
    width: 100px;
    height:40px;
}
#btn:hover{

    background-image: url('images/button_hover.jpg');
}

#btn:active{
    background-image: url('images/button_active.jpg');
}

1 Comment

just keep in mind that :hover is not supported in IE6 for elements different than <a>

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.