Firefox 的条件 css 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4575674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:23:52  来源:igfitidea点击:

conditional css statement for firefox

cssfirefoxconditional

提问by Dan Stern

I'm having problems with css in firefox, therefore I want to import a css file only if the browser is FF

我在 firefox 中遇到 css 问题,因此我只想在浏览器为 FF 时导入 css 文件

Actually, I need to import this styles:

实际上,我需要导入这种样式:

.searchbutton{
    position:absolute; right:3px;  width:25px;  
    top:3px;
}

#buscarmain{ bottom:12px;

}

EDIT:

编辑:

Many have argued that I shouldn't use a special statement for FF, since FF is most probably to be correct, compared to other browsers.

许多人认为我不应该对 FF 使用特殊声明,因为与其他浏览器相比,FF 最有可能是正确的。

However, in this case all browsers print the same page (IE, Chrome, Opera, Safari) and FF displays it in another way. I must achieve the same visualization for all browsers, therefore I need a special FF statement

但是,在这种情况下,所有浏览器都打印相同的页面(IE、Chrome、Opera、Safari)并且 FF 以另一种方式显示它。我必须为所有浏览器实现相同的可视化,因此我需要一个特殊的 FF 语句

采纳答案by Dan Stern

solved the problem

解决了问题

just added:

刚刚添加:

    <script type="text/javascript">
    if ( $.browser.mozilla == true ) {
      document.write("<link type=\"text/css\" rel=\"stylesheet\" href=\"FF.css\">");
    }
</script>

回答by J. Bruni

Here is how we can target CSS styles only for Firefox:

以下是我们如何仅针对 Firefox 定位 CSS 样式:

<style type="text/css">
@-moz-document url-prefix() {
    h1 {
        color: red;
    }
}
</style>

Source: Targeting only Firefox with CSS

来源:仅使用 CSS 定位 Firefox

回答by Xuni

You might try the css browser selector

您可以尝试使用css 浏览器选择器

回答by James Long

IE is the only browser with conditional comments. I've always felt that every browser should have their own, but alas.

IE 是唯一带有条件注释的浏览器。我一直觉得每个浏览器都应该有自己的,可惜。

I think the solution is to tweak your style sheet so that it displays properly in Firefox and then fix for IE.

我认为解决方案是调整您的样式表,使其在 Firefox 中正确显示,然后针对 IE 进行修复。

A rough and very dirty solution would be to use JavaScript to detect the browser and add a class such as "ffonly" to the body tag if the browser is Firefox. Then always bring in your Firefox stylesheet but put ".ffonly " at the begining on all your style rules

一个粗略且非常脏的解决方案是使用 JavaScript 来检测浏览器,如果浏览器是 Firefox,则将诸如“ffonly”之类的类添加到 body 标记中。然后始终引入您的 Firefox 样式表,但在所有样式规则的开头放置“.ffonly”