How to provide CSS properties for Different browsers like Mozilla and Chrome


Tags: css,browser

Problem :

If I would like to give a unique property to a page (say index.html) for different browsers. For example : Blue background for Chrome and Red Background for Firefox, then how can I write a CSS code to this case?



Solution :

Using CSS Media Queries (Chrome/Safari)

@media not all and (-webkit-min-device-pixel-ratio:0)
{  
    #example
    {
        width: 200px;
    }
}

Chrome/Safari specific css file (Chrome/Safari)

<link rel="stylesheet" href="style-sheet_chrome.css" type="text/chrome/safari" />

Here is a CSS Hacks list

/***** Selector Hacks ******/

/* IE6 and below */
* html #uno  { color: red }

/* IE7 */
*:first-child+html #dos { color: red } 

/* IE7, FF, Saf, Opera  */
html>body #tres { color: red }

/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body #cuatro { color: red }

/* Opera 9.27 and below, safari 2 */
html:first-child #cinco { color: red }

/* Safari 2-3 */
html[xmlns*=""] body:last-child #seis { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) #siete { color: red }

/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type #ocho {  color: red }

/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}

/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}


/* Safari 2 - 3.1 */
html[xmlns*=""]:root #trece  { color: red  }

/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""] #catorce { color: red  }

/* Everything but IE6-8 */
:root *> #quince { color: red  }

/* IE7 */
*+html #dieciocho {  color: red }

/* Firefox only. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }

/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }



/***** Attribute Hacks ******/

/* IE6 */
#once { _color: blue }

/* IE6, IE7 */
#doce { *color: blue; /* or #color: blue */ }

/* Everything but IE6 */
#diecisiete { color/**/: blue }

/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }

/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }

/* IE6, IE7 -- acts as an !important */
#veintesiete { color: blue !ie; } /* string after ! can be anything */

    CSS Howto..

    Links fade in when hovered - how to get them to stay opaque when their target is visible?

    bootstrap navbar how to give it a max width

    How to select -webkit-filter: drop-shadow with jQuery?

    How to make a number of breaks in CSS? [closed]

    How to extend a wrapped element background both left and right with different color?

    Zend_Form - add CSS Class :: How can I add css class to label in Zend_Form?

    bootstrap select show only dropdown-menu on link click without the select button

    JQuery with IE reading inherted css property, how to prevent?

    How can I change GWT's widget CSS values?

    How do I prevent it from newlining in html?

    How to prevent HTML code in a literal inside a DIV from affecting outer page styles

    How to get css or java class for specific part of code

    How to generate assets that match the html file of a rails application?

    How to start ordered list from 2 not 1 with w3c validity and IE 6 compatibility?

    How to downsize a larger image while showing only one portion of it in CSS (or adding JS to the mix if necessary)?

    How to hover a whole element to show details

    How to brighten Textbox when it is focused?

    How to apply the CSS of navbar-inverse in twitter-bootstrap

    How to display a portion of an image with CSS?

    How can I use PHP code in a CSS file

    How to use a jQuery variable in CSS property

    How To Add Links To Right Of Header?

    In a text based browser game, how would I make a typewriter effect in the dialogue?

    How To Set Height of Child Div According To Parent Div

    How do I add custom fonts? [duplicate]

    CSS How to get the same height?

    How to Target Twitter Bootstrap <768px and 480px Breakpoints

    CSS: How to make a block to cover all width of parent block

    How to enable top and bottom margins between a series of spans inside a div?

    How to make the CSS “~” selector work in GWT Css Resource