简体   繁体   English

html输入按钮样式CSS3

[英]html input button style CSS3

I saw some results via the related questions but didn't actually seem to show what I want. 通过相关问题,我看到了一些结果,但实际上并没有显示我想要的结果。 Looking for a way to simply style the button in all major broswers easily. 寻找一种简单地在所有主要浏览器中设置按钮样式的方法。

<input type="file" name="file" id="file" size="29" class="formButton" /> 
<span class="smalltext">(.txt only)</span>

I want the browse button to use the CSS, I have seen some results that put a fake button on top of the real one, is that really the best approach to take? 我希望浏览按钮使用CSS,我已经看到一些结果,将假按钮置于真实按钮之上,这真的是最好的方法吗?

Currently, there's no way to consistently style a file input field across browsers. 当前,无法在所有浏览器中统一设置文件输入字段的样式。 You could use one of the various "tricks" out there (which as you mentioned simply overlay the button), but beware that you might interfere with keyboard access to the field. 您可以使用各种“技巧”之一(如您所提到的那样简单地覆盖按钮),但要注意,这可能会干扰键盘对字段的访问。

Don't try this! 不要尝试这个!

Even if you get it working, there's still browsers like Safari that use non-standard file selection widgets! 即使您可以使用它,仍然有像Safari这样的浏览器都使用非标准的文件选择小部件!

It's best to let the native file widget show through. 最好让本机文件窗口小部件显示出来。

The best solution I've found is to either overlay your own as you've mentioned, or use something like Dojo, which effectively does the same thing. 我发现最好的解决方案是要么像您提到的那样叠加您自己的东西,要么使用Dojo之类的东西来有效地完成相同的事情。 As far as I know, you can't style the file input button. 据我所知,您无法设置文件输入按钮的样式。

Actually, with JqueryUI you can do it by simply: 实际上,使用JqueryUI可以通过以下简单操作来实现:

Javascript for rollover (not required): 用于过渡的Javascript(不是必需的):

$(".fg-button:not(.ui-state-disabled)")
                .hover(
                    function(){ 
                        $(this).addClass("ui-state-hover"); 
                    },
                    function(){ 
                        $(this).removeClass("ui-state-hover"); 
                    }
                )

Button Code: 按钮代码:

<input type="submit" name="something" id="something" value="Submit" class="fg-button ui-state-default ui-corner-all">

Not that due to IE being a Microsoft product, the rounded corners gracefully degrade. 并不是说由于IE是Microsoft产品,圆角会优雅地降低。

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

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