Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i adjust the button size according to image size?

For ex: if i have applied 24*24 image then button should auto resize it self according
to image.

how is this possible?
Posted
Comments
ldsroshan 19-May-12 8:00am    
You mean if the image is 1024*1024 then button should be the same.......!
I don't think that is a good idea. It better to keep a fixed size.

1 solution

When you assign an image to a button, it uses the background-image CSS feature. This doesn't have the stretch/auto-size feature you're looking for.

If you have access to the image on the server-side you can load it into a Bitmap object which will give you the width and height. You can then use this when rendering the page to get the correct size.

Another approach would be to use a div and an img tag. Something like this:

XML
<div style="width: auto; height: auto;" onclick="doButtonAction();"><img src="images/image.png" /></div>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900