Alex Rivera | Logout

How to make CSS visible only for Opera

Asked 2009-07-13T15:55:05.447
32

Is there a way to make some CSS rules visible only for Opera?

Edit
Report

2 Answers

1

The only way I can think of is to check the user agent and only reference the style sheet when it's an opera browser. Since the user agent can be messed with this might not be 100% reliable.

answered 2009-07-13T16:00:07.560
1

You can use javascript to write out a <link> to include a specific CSS file.

if (navigator.userAgent.indexOf(’Opera’) != -1) {
    document.write(””);
}
else {
    document.write(””);
}

For Opera 7 you can use this:

/*Visible to only Opera*/
@media all and (min-width: 0) {
    /* css rules here */
}

However, it's generally bad practice to do styling based on browser-sniffing.

answered 2009-07-13T16:02:26.900

Your Answer