-1

Is there a way to choose background-color with a browser condition?

I want to do something like this:

browser.css

-o-background-color: red;
-moz-background-color: green;
-webkit-background-color: blue;

If the condition could be in CSS it will be better. If it's not possible, it can be in Javascript also.

But first, is this condition possible?

Thanks!!

Johnson
  • 1,396
  • 6
  • 17
  • 36

2 Answers2

1

Refer to this: How to detect Safari, Chrome, IE, Firefox and Opera browser?

You can then add a simple conditional statements and use the DOM to change the background color.

charAt
  • 39
  • 9
1

You can identify the browser used by your visitors using the window object: e.g.

window.navigator.vendor

or

window.navigator.userAgent

Then you can modify or add a new stylesheet to the page.

sashaikevich
  • 167
  • 13
  • Thanks a lot! But Is possible to use only `CSS`? – Johnson Dec 13 '17 at 16:00
  • 1
    I don't think so. I know you can use conditional comments in html (more info here: https://www.quirksmode.org/css/condcom.html), but that's only for IE, not for opera / firefox / safari. @charAt's link is good, as it gives you the code you can copy and paste for the most part. Also, you might want to check out this wiki: https://www.w3.org/community/webed/wiki/Optimizing_content_for_different_browsers:_the_RIGHT_way if you want to read up on all the different approaches. – sashaikevich Dec 13 '17 at 17:09