Applying CSS to Opera only
[Edit: 080828] This hack targets only Opera 9 and below, but fails in (at least) v9.52. You should not use it unless you're specifically targeting Opera 9 and below.
If you ever need to apply certain styles to Opera only, there is an easy way that I found in Jeff Starr's post, 'CSS Hack Dumpster'. All you need to do is prefix your selector with html:first-child
.
For example, let's see how you would add a left margin of 10px to all paragraphs in all browsers except Opera:
p {
margin-left: 10px;
}
html:first-child p {
margin-left: 0;
}
This hacks validates and seems reasonably safe. As always, it's a risk to use hacks in your CSS (what would happen if, say, Internet Explorer 12 matched html:first-child? Any websites using this hack wouldn't work correctly in IE12). I'm still going to use it though, it seems quite safe to me.
Posted 080815, in: English, Web, CSS
Tags: css hacks, Opera
Post links: