简体   繁体   English

HTML - 样式表单按钮

[英]HTML - Styling a Form Button

I'm trying to style my submit button for my form. 我正在尝试为我的表单设置提交按钮的样式。 I was looking into the 'button' tag, and adding in my CSS style, but the button still has a horrible default style. 我正在查看“按钮”标签,并添加我的CSS样式,但按钮仍然有一个可怕的默认样式。

This is what I have so far: 这是我到目前为止:

<button name="visit_return_button" id="visit_return_button" type="submit" class="visit_return_button">
Increase
</button>

My css style is working, but I also get a nasty looking border and background colour. 我的css样式正在运行,但我也看到了令人讨厌的边框和背景颜色。 I was looking into JavaScript too, but I don't like the idea that not all browsers have JS active. 我也在研究JavaScript,但我不喜欢并非所有浏览器都有JS活动的想法。

Below is an image of the button, the top one is what it looks like, the bottom one is what its suppose to look like: 下面是按钮的图像,顶部是它的样子,底部是它的样子:

在此输入图像描述

Here is my CSS: 这是我的CSS:

#visit_return_button{
    width:90px;
    height:30px;
    position:absolute;
    background-image: url(image/build_button.png);
    background-repeat: no-repeat;
    /*font-family: Tahoma, Geneva, sans-serif;*/
    font-size: 14px;
    font-weight: normal;
    color: #FFF;
    text-align: center;
    /*margin: auto;*/
    padding-top: 10px;
    margin-top:-20px;
}

Would appreciate any help, thanks 非常感谢任何帮助,谢谢

Either try to hide the border like border:0; 尝试隐藏borderborder:0; and adjust the background to fit your needs or do not use a background image and try to do it with pure css and border-radius which seems to be a better idea. 并调整背景以满足您的需要或不使用背景图像并尝试使用纯css和border-radius ,这似乎是一个更好的主意。 See http://jsfiddle.net/qVkRs/1/ http://jsfiddle.net/qVkRs/1/

First you want to make a global style for your buttons, otherwise you will have to apply those styles to every single button id which will be a lot of repeated css. 首先,您要为按钮创建一个全局样式,否则您将必须将这些样式应用于每个按钮ID,这将是很多重复的CSS。 Then change your background styles to be like below. 然后将您的背景样式更改为如下所示。 After that, you can adjust the rest to look correct. 之后,您可以调整其余部分以使其正确无误。

input[type="button"], input[type="submit"], button
{
     background: none;
     background-image: url(image/build_button.png);
     background-position: center center;
     background-repeat: no-repeat;
     border: 0px;
     /* add the rest of your attributes here */
}

This will apply these styles to all buttons across the entire site. 这会将这些样式应用于整个站点的所有按钮。 If you need to apply additional styles to a specific button or override some of the above, then use the id and place it below the above code. 如果您需要将其他样式应用于特定按钮或覆盖上述某些按钮,请使用该ID并将其置于上述代码下方。 Also get rid of the class="" attribute on your button tag, you don't need it and it is not being used as far as we can see. 还要删除按钮标记上的class =“”属性,您不需要它,并且我们可以看到它没有被使用。 Hope this helps. 希望这可以帮助。 Good Luck! 祝好运!

I think you're trying to remove the border. 我想你正试图删除边界。 This can be done with: 这可以通过以下方式完成:

border:none;

I took the liberty of tidying up the original CSS here: 我冒昧地整理了原来的CSS:

#visit_return_button{
    width:90px;
    height:30px;
    font:14px Tahoma, Geneva, sans-serif;
    background:url(image/build_button.png) no-repeat;
    color:#fff;
    text-align:center;
    border:none; /* removal of border */
}

Also if this is a form, it is be better to use: 此外,如果这是一个表单,最好使用:

<input type="button" value="Increase"/>

for buttons; 按钮; and: 和:

<input type="submit" value="Increase"/>

for SUBMIT buttons specifically. 特别是对于SUBMIT按钮。

只需隐藏按钮的边框并设置背景颜色即可

background:#ffffff url('your_image.png');

Here's my solution; 这是我的解决方案; I've tested with all the major browsers and it works fine, even without the background picture. 我已经测试了所有主流浏览器,它工作正常,即使没有背景图片。 Except IE8 doesn't do rounded corners. 除了IE8不做圆角。

http://jsfiddle.net/uSphG/3/ http://jsfiddle.net/uSphG/3/

I added some style properties, just in case. 我添加了一些样式属性,以防万一。 Some features have different defaults on different browsers. 某些功能在不同的浏览器上有不同的默认值。

button::-moz-focus-inner {
 padding: 0 !important;
 border: none !important;
}

#visit_return_button{
 display:inline-block;
 width:90px;
 padding:0; margin:0; outline:0;
 background:#9B8C47;
 background-image: url(image/build_button.png);
 background-repeat: no-repeat;
 /*font-family: Tahoma, Geneva, sans-serif;*/
 border:1px solid #866517;
 -moz-border-radius:0.4em;
 border-radius:0.4em;
 font-size: 14px; line-height:24px;
 font-weight: normal;
 color: #FFF;
 text-align: center;
 /*margin: auto;*/
}

You can easily make your button through CSS3 Border-Radius property:- 您可以通过CSS3 Border-Radius属性轻松制作按钮: -

CSS CSS

 #visit_return_button{
    background-color:#9C8C42;
    border: 2px solid #91782c;
    color: #FFF;
    text-align: center;
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    padding: 10px;
    }

HTML HTML

<button id="visit_return_button" type="submit">Increase</button>

demo:- http://jsfiddle.net/VY8xs/3/ 演示: - http://jsfiddle.net/VY8xs/3/

Libraries are often a good solution for styling buttons consistently across multiple browser types. 对于跨多种浏览器类型一致的样式按钮,库通常​​是一个很好的解决方案。 Check out jQuery buttons , YUI Buttons , and there are many others as well. 查看jQuery按钮YUI按钮 ,还有很多其他 按钮

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

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