-1

我想创建带有一些文本的 HTML 按钮,并且还想为该按钮放置背景图像。我正在尝试以下代码,但那不起作用。我已将 test.png 放在我的 www 目录中

<!DOCTYPE html>
<html>
<body>
<input type="button" name="test" value="test" style="background:url('test.png') no-repeat 0 0; width:100px;height=50px;background-color: transparent" ></input>
</body>
</html>
4

5 回答 5

0

您已经像这样定义了高度,height=50px;这是错误的语法。

在 style 属性中编写 css 时的正确语法:height:50px;

编辑:

还要检查图像的路径是否正确或图像存在于给定路径上。

于 2013-05-28T09:07:35.140 回答
0

我使用了以下 HTML,一切正常。

<input type="button" name="test" value="test" style=" background: url('http://www.training-industry.co.uk/assets/images/Take_Test.png') no-repeat 0 0;
width:130px;
height:130px;
background-color: transparent;" />

看看这个小提琴并与您的代码进行比较:http: //jsfiddle.net/ssqfK/1

于 2013-05-28T09:22:23.887 回答
-1

尝试background-image代替background

于 2013-05-28T09:04:31.247 回答
-1

background:url('test.png') no-repeat 0 0; width:100px; height=50px; background-color: transparent

应该:

background:transparent url('test.png') no-repeat 0 0; width:100px; height:50px;"

附带说明一下,您应该尽可能避免使用内联样式。

于 2013-05-28T09:06:50.683 回答
-1

试试这个 :

<input type="button" name="test" value="test" style="background:transparent url('test.png') no-repeat 0 0; width:100px;height:50px;" />

另外,请注意 height:50px 而不是 height=50px

于 2013-05-28T09:07:54.590 回答