Device detecting Conditional css

11,442

There is no way of detecting an operating system or web browser using strictly CSS.

I'd recommend using Javascript to detect the web browser / operating system, and attach classes to the <body> of the page accordingly.

You can then write CSS specific to each use case, which will only be honored if that particular criteria is encountered.

Here is an example on jsFiddle.

Share:
11,442
user1853128
Author by

user1853128

Updated on November 24, 2022

Comments

  • user1853128
    user1853128 over 1 year

    I am trying to add some conditional css for device detecting, because of some conflicts in desktop and android tablet landscape res

    - if android_device?
            :css
    
              @media only screen and (max-width : 1280px) and (-webkit-device-pixel-ratio:2)  {
    
                /*CSS*/
              }
    

    can any one help me out where I have to use this check?

    I got this reference from this url: URL

    • user1721135
      user1721135 over 10 years
      if android_device? - what is this?
    • John Magnolia
      John Magnolia about 10 years
      Only Microsoft think: 'we usually get it wrong, so lets include a way for devs to fix our issues'
  • Makita
    Makita over 10 years
    This doesn't address detecting android devices, only screen width.