简体   繁体   English

如何在提交按钮中设置背景图像?

[英]how to set background image in submit button?

how to set background image in submit button? 如何在提交按钮中设置背景图像?

I have to use a image in place of regular submit button? 我必须使用图像代替常规提交按钮? which way would be best in xhtml/css? 在xhtml / css中哪种方式最好?

Button should look same in all main browsers including IE6,IE7 在所有主流浏览器中,按钮应该看起来相同,包括IE6,IE7

The way I usually do it, is with the following css: 我通常这样做的方式是使用以下css:

div#submitForm input {
  background: url("../images/buttonbg.png") no-repeat scroll 0 0 transparent;
  color: #000000;
  cursor: pointer;
  font-weight: bold;
  height: 20px;
  padding-bottom: 2px;
  width: 75px;
}

and the markup: 和标记:

<div id="submitForm">
    <input type="submit" value="Submit" name="submit">
</div>

If things look different in the various browsers I implore you to use a reset style sheet which sets all margins, padding and maybe even borders to zero. 如果各种浏览器中的内容看起来不同,我恳请您使用重置样式表,将所有边距,填充甚至边界设置为零。

Typically one would use one (or more) image tags, maybe in combination with setting div background images in css to act as the submit button. 通常,人们会使用一个(或多个)图像标签,可能与在css中设置div背景图像组合起来作为提交按钮。 The actual submit would be done in javascript on the click event. 实际提交将在点击事件的javascript中完成。

A tutorial on the subject. 关于这个主题的教程

.button {
    border: none;
    background: url('/forms/up.png') no-repeat top left;
    padding: 2px 8px;
}

我喜欢这个封面按钮和中间图像

<button><img src="foldername/imagename" width="30px" height= "30px"></button>

您可以尝试以下代码:

background-image:url('url of your image') 10px 10px no-repeat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM