如何根据图像尺寸调整按钮尺寸? [英] How to adjust the button size according to image size?

查看:128
本文介绍了如何根据图像尺寸调整按钮尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据图像大小调整按钮大小?

例如:如果我已应用24 * 24图像,则按钮应根据自己自动调整其大小
到图像.

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?

推荐答案

将图像分配给按钮时,它会使用背景图像CSS功能.该功能没有您要查找的拉伸/自动调整大小功能.

如果您可以访问服务器端的图像,则可以将其加载到Bitmap对象中,该对象将为您提供宽度和高度.然后,您可以在呈现页面时使用它来获取正确的大小.

另一种方法是使用div和img标签.像这样的东西:

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:

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


这篇关于如何根据图像尺寸调整按钮尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆