Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a CSS media query to detect Windows?

I want to specify two slightly different background colors, one for Mac OS, one for Windows.

like image 577
colmtuite Avatar asked Dec 13 '11 17:12

colmtuite


People also ask

What is CSS media query used for?

Using media queries are a popular technique for delivering a tailored style sheet (responsive web design) to desktops, laptops, tablets, and mobile phones. You can also use media queries to specify that certain styles are only for printed documents or for screen readers (mediatype: print, screen, or speech).

Do media queries go in CSS?

Media queries are commonly associated with CSS, but they can be used in HTML and JavaScript as well. There are a few ways we can use media queries directly in HTML.


1 Answers

there is no property to specify OS used to view webpage, but you can detect it with javascript, here is some example for detecting Operating system :

var OSName="Unknown OS"; if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS"; if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";  console.log('Your OS: '+OSName); 

got it?, now you can play with document.write to write download stylesheet for specific Operating system. :)

another example, i assumed that you are using jquery.

if (navigator.appVersion.indexOf("Win")!=-1)  {   $(body).css('background','#333'); } else {   $(body).css('background','#000'); // this will style body for other OS (Linux/Mac) } 
like image 184
Ariona Rian Avatar answered Sep 17 '22 20:09

Ariona Rian