无法使我的按钮在不同浏览器中看起来相同
我不太擅长网页设计,我使用 CSS 创建了一个按钮,但我不知道如何使其在不同的浏览器中看起来相同。
这是我使用的按钮:
<input type="submit" class="randombutton" value="click here!"/>
这是我创建的 css:
.randombutton {
border-top: 1px solid #d1d425;
background: #e6eb4c;
background: -webkit-gradient(linear, left top, left bottom, from(#92b019), to(#e6eb4c));
background: -webkit-linear-gradient(top, #92b019, #e6eb4c);
background: -moz-linear-gradient(top, #92b019, #e6eb4c);
background: -ms-linear-gradient(top, #92b019, #e6eb4c);
background: -o-linear-gradient(top, #92b019, #e6eb4c);
padding: 19px 38px;
border-radius: 40px;
color: white;
font-size: 23px;
font-family: Georgia, Serif;
text-decoration: none;
vertical-align: middle;
display: block;
margin-left: auto;
margin-right: auto;
}
.randombutton:hover {
border-top-color: #c0df36;
background: #c0df36;
color: white;
}
.randombutton:active {
border-top-color: #9eb829;
background: #9eb829;
}
这是我在 3 个不同浏览器中得到的结果:
另外我想提一下,我无法将按钮置于屏幕中间。
该按钮应类似于为 Chrome 浏览器粘贴的图像。我将不胜感激一些帮助。
I am not very good at web design, I created a button using CSS but I don't know how to make it look the same in different browsers.
This is the button I use:
<input type="submit" class="randombutton" value="click here!"/>
This is the css I created:
.randombutton {
border-top: 1px solid #d1d425;
background: #e6eb4c;
background: -webkit-gradient(linear, left top, left bottom, from(#92b019), to(#e6eb4c));
background: -webkit-linear-gradient(top, #92b019, #e6eb4c);
background: -moz-linear-gradient(top, #92b019, #e6eb4c);
background: -ms-linear-gradient(top, #92b019, #e6eb4c);
background: -o-linear-gradient(top, #92b019, #e6eb4c);
padding: 19px 38px;
border-radius: 40px;
color: white;
font-size: 23px;
font-family: Georgia, Serif;
text-decoration: none;
vertical-align: middle;
display: block;
margin-left: auto;
margin-right: auto;
}
.randombutton:hover {
border-top-color: #c0df36;
background: #c0df36;
color: white;
}
.randombutton:active {
border-top-color: #9eb829;
background: #9eb829;
}
This is the result I get in 3 different browsers:
Also I would like to mention that I can't center the button in the middle of the screen.
The button should look like the image for pasted for the Chrome browser. I'll appreciate some help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
作为互联网浏览器< 9 不知道圆角,您将无法在 IE 中执行此操作,因为渐变更有可能在每个浏览器中得到不同的结果。
最佳实践是制作图像并向其中添加自定义设计,然后插入提交作为图像
As internet explorer < 9 doesn't know about round corners you will not be able to do that in IE, as for gradient is more likely you will get different results in every browser.
The best practice is to make an image and add your custom design to it and then insert submit as an image
带有圆角和渐变的按钮很难跨浏览器,当你还必须照顾 IE 时。
对于 Firefox,只需添加
-moz-border-radius: 40px;
即可使其看起来像在 Chrome 上。对 IE 的渐变支持是通过 DX 图像变换完成的。
跨浏览器CSS渐变给出了如何实现跨浏览器渐变的示例。
编辑:但是,Mihai 是正确的,最好通过图像而不是按钮来实现结果,因为它的外观不依赖于引擎/浏览器。
A button with rounded corners and gradient is very hard to do cross browser, when you have to take care of IE as well.
As for Firefox, just add
-moz-border-radius: 40px;
to make it look like on Chrome.The Gradient support for IE is done through DX Image Transforms.
Cross Browser CSS Gradient gives an example how to achieve gradients cross browser.
Edit: However, Mihai is correct, it would be best to achieve the result through an image instead of a button, since it's looks are not engine-/browser-dependent.
我建议使用像 http://border-radius.com/ 这样的边框半径生成器来设置圆角,它会给你你所缺少的额外值(注意顺序很重要):
至于使其在浏览器中看起来相同,使用按钮这是一个痛苦的世界,所以你有两个主要选择:
就我个人而言,我首先尝试避免重新设计表单元素,因为它很昂贵(时间成本因为很难做到)并且不可靠。别管他们,用户只是不会注意到他们,这很好 - 他们在网络上完成工作:)
I would suggest using a border-radius generator like http://border-radius.com/ to set up the rounded corners, it'll give you the extra values you're missing (note the order is significant):
As for making it look the same across browsers, with buttons it's a world of pain so you have two main options:
Personally I try to avoid restyling form elements in the first place, because it expensive (time cost because it's hard to do) and unreliable. Leave them alone and users just don't notice them, which is fine - they're on the web to get things done :)