如何制作CSS“if opera,not...”

发布于 2024-10-06 14:53:31 字数 261 浏览 0 评论 0原文

我想制定一个css规则,它影响除opera浏览器之外的所有浏览器,所有其他浏览器都添加一个css规则:

#content{left:1px;},(opera没有此规则)。下面的代码不起作用...

<!--[if !OPERA]> 
<style type="text/css">
#content{left:1px;} 
</style>
<![endif]-->

I want to make a css rule, which affects all but the opera browser, all the other browser add a css rule:

#content{left:1px;}, (opera without this rule). the below code not worked...

<!--[if !OPERA]> 
<style type="text/css">
#content{left:1px;} 
</style>
<![endif]-->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

焚却相思 2024-10-13 14:53:31

条件注释仅被 IE 识别。如果您需要 Opera 特定的 CSS,您将需要 JavaScript:

if (window.opera) {
    document.getElementById('foo').style.height = '100px';
}

Conditional comments are recognized by IE only. If you need Opera-specific CSS, you will need JavaScript:

if (window.opera) {
    document.getElementById('foo').style.height = '100px';
}
思慕 2024-10-13 14:53:31

您可以使用您想要的选择器属性,例如 #content{left:1px;},然后为 opera 添加 css hack,提供默认值(或您想要的值)。 css hack 具有以下语法: @media all and (min-width:0px) {head~body .selector {property:value;}} 前面语法的示例,您的示例可以是: @media all 和 (min-width:0px) {head~body #content {left:0px;}}

you can use the property you want for a selector like #content{left:1px;} then add a css hack for opera providing the default value (or the value you want). The css hack has the following syntax: @media all and (min-width:0px) {head~body .selector {property:value;}} an example of the previous syntax and your example could be: @media all and (min-width:0px) {head~body #content {left:0px;}}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文