[CSS] How to Use Browser-Specific CSS Hacks.

reloadmydeagle Jan 21, 2015

  1. reloadmydeagle

    reloadmydeagle I LoVe GoldZ Lifetime Gold XPG Retired Staff
    205/282

    Joined:
    Oct 30, 2013
    Messages:
    1,608
    Likes Received:
    656
    Trophy Points:
    135
    Gender:
    Male
    Location:
    Texas
    Console:
    Xbox One
    When coding in HTML5 and CSS3, you will almost always encounter errors with code being read differently in different browsers. This particularly happens with CSS3 coding, which certain browsers interpret differently, which can result in a different looking webpage on certain browsers.

    To achieve unity, there's a miracle called browser-specific CSS hacks to help you target the errors in certain browsers and correct them. The hacks allow you to apply CSS to a certain browser, without applying it to another. This is great for getting a webpage to look identical in all browsers.

    Full list of CSS hacks:
    /***** 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 */

    To use them, simply change the class/id tag to whatever HTML element you are manipulating, apply the CSS needed to correct the browser-specific error, and save in your CSS file. Simple as that!

    Hope you enjoyed my run-down of CSS hacks, and please feel free to leave any questions below!
     
  2. prodigy

    prodigy Trusted Seller since 2014 :)
    95/188

    Joined:
    Jul 7, 2014
    Messages:
    1,490
    Likes Received:
    357
    Trophy Points:
    95
    Gender:
    Male
    Occupation:
    Call of Duty Recovery Seller
    Location:
    Boston, Ma
    Console:
    Computer
    Interesting nice share Rifter.
     
  3. XxStarzxX

    XxStarzxX Banned! BANNED
    205/282

    Joined:
    Mar 3, 2012
    Messages:
    6,119
    Likes Received:
    1,136
    Trophy Points:
    205
    Gender:
    Male
    Location:
    XPG
    Console:
    Xbox One
    Great share Rifter ;)
     

Share This Page

Close