在asp.net中将背景图像设置为按钮标签 [英] setting backgroung image to button tag in asp.net

查看:59
本文介绍了在asp.net中将背景图像设置为按钮标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将图像设置为asp.net中的button标记,但是它给出了一个错误,提示无法将background-image应用于.请帮忙我写了下面的代码

i tried to set image to the button tag in asp.net but it gave an error saying background-image cannot be applied to . Please help I wrote the following code

<asp:Button ID="bsrc" runat="server" Style="left: 545px; position: absolute; top: 18px;font-family:Tahoma; font-size:small" Text="Search" Width="101px" />
<img src="search-icon.png" alt="" style="left: 649px; width: 29px; position: absolute; top: 17px; height: 26px" />

推荐答案

有一个名为ImageButton的asp.net控件,看起来好像是您要使用的控件.

There is an asp.net control called ImageButton which looks as though it is what you are wanting to use.

<asp:ImageButton id="bsrc" runat="server" ImageUrl="search-icon.png" />

而不是使用按钮然后尝试为其提供图像.

Rather than using a button and then trying to give it an image.

要显示文本,您不能使用ImageButton.因此,您将需要使用一些CSS来获得按钮的背景图片.

To display text, you can't use the ImageButton. So you will need to use some css to achive the background image of the button.

CSS

.btnstyle1{ background: url(yourimageurl.jpg); height: imageheight; width: imagewidth; }

按钮

<asp:Button ID="btn1" runat="server" Text="Button 1" CssClass="btnstyle1" />

这篇关于在asp.net中将背景图像设置为按钮标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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