Max Z.
Max Z.

Reputation: 811

Browser specific CSS

I want to use fonts on my website which look great in Firefox, but broken up on Chrome and IE. Now to avoid this issue I wanted to change the font family for only Chrome and IE. There is the [if IE] statement for IE support, but is there one for Chrome (and possibly more browsers), too?

Upvotes: 0

Views: 1882

Answers (4)

Peter MK
Peter MK

Reputation: 133

Simple solution, just use this JS library and you can easily apply styles for every browser/os combination:

BrowserClass.js

With this you will get a class name on the body tag with the current name and version of the browser also with the used OS.

After include the file:

<script src="js/browserclass.js"></script>

For example on Windows 8.1 with the latest chrome you will see:

<body class="chrome chrome34 win desktop">

And in your style file you can refer by: (.sass styling)

body.chrome
  #example
    color: blue

or

body.win.chrome
  #example
    color: red

Note:

[if IE] statements deprecated since IE10 so this is the solution for that

Upvotes: 2

Cecil Theodore
Cecil Theodore

Reputation: 9949

This site is very helpful

http://paulirish.com/2009/browser-specific-css-hacks/

Upvotes: 0

David Hor&#225;k
David Hor&#225;k

Reputation: 5565

jQuery.browser

Available flags are:

  • List item
  • webkit (as of jQuery 1.4)
  • safari (deprecated)
  • opera
  • msie
  • mozilla

Use Example:

  if ($.browser.webkit) {
    alert( "Set up your font css" );
  }

Upvotes: 4

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324820

No, only IE supports conditional comments.

However, I would advise against any browser-specific code. As a developer it's up to you to ensure your site looks equally good in as many browsers as possible.

If you really want conditional code, use browser detection (ie. search the user agent string for fragments that identify the browser)

Upvotes: 3

Related Questions