Browser specific CSS padding for firefox field

泄露秘密 提交于 2019-12-30 02:02:05

问题


I have a dropdown list in my application whereby in order to center it I must add padding-top 10px while on Mozilla Firefox but on google chrome it does not need the padding. How can I target the select list to set this browser specific. I was hoping I could have done something like the following:

select {
  -moz-padding-top: 10px;
  -webkit-padding-top: 0px;
}

Any ideas of how I could get round this? Fiddle of problem shown below, if you check this in Chrome and then Firefox, I want it so that text is always in middle

http://jsfiddle.net/uHDa6/


回答1:


Note: the first part of this answer is now obsolete, as this feature has been removed from Firefox. For the real answer, read on from "However".


The answer to your question is: yes, it's possible to put Mozilla-specific CSS in a stylesheet. (Not in an inline style attribute.)
In this case, you would write

@-moz-document url-prefix() {
    select {padding-top:10px;}
}

which is simply the Mozilla-prefixed version of the @document rule, that is not recognised by other browsers.


However, the actual solution to the problem of the mismatched text position is to not set the height, but only the padding of the select. No hacks.

style="font-size: 14px; padding: 11px 0 11px 5px;"

That has the desired effect in all browsers. See new fiddle.



来源:https://stackoverflow.com/questions/19569399/browser-specific-css-padding-for-firefox-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!