@media screen and (-moz-windows-theme) {
.windows {
color:red;
}
}
同样地,这个适用于除Windows外的任何操作系统,同样适用于Firefox 4及更高版本:
@media not screen and (-moz-windows-theme) {
_:-moz-ui-valid, .nonwindows {
color:red;
}
}
-moz-os-version是在Firefox 25中添加的媒体查询,但根据Mozilla文档,它只有几个选项,网址为https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries
操作系统:windows-xp | windows-vista | windows-win7 | windows-win8 | windows-win10
因此,这个集合仅适用于现代Firefox浏览器版本>= 25。在发布此更新时,Firefox的版本为35。
@media screen and (-moz-os-version:windows-xp) {
.windows,.winxp {
color:red;
}
}
@media screen and (-moz-os-version:windows-vista) {
.windows,.vista {
color:red;
}
}
@media screen and (-moz-os-version:windows-win7) {
.windows,.win7 {
color:red;
}
}
@media screen and (-moz-os-version:windows-win8) {
.windows,.win8 {
color:red;
}
}
@media screen and (-moz-os-version:windows-win10) {
.windows,.win10 {
color:red;
}
}
微软的Edge浏览器(原名斯巴达)目前仅适用于Windows 10。要检测它:
/* Microsoft Edge Browser */
@supports (-ms-ime-align:auto) {
.windows,.win10 {
color:red;
}
}
@media screen and (-moz-overlay-scrollbars) {
.mac,.mac10_7up {
color:red;
}
}
Firefox >= 25也有一种方法来检测Mac OS X,因为他们在版本25中添加了对OS X字体平滑的支持:
@supports (-moz-osx-font-smoothing:auto) {
.mac,.mac10_6up {
color:red;
}
}
@supports (-moz-osx-font-smoothing:auto) {
@media not all and (-moz-overlay-scrollbars) {
.mac,.mac10_6 {
color:red;
}
}
}
Firefox 17 及以上版本仅支持 Mac OS X 10.6+ (雪豹及更新版本),因此,如果您得到任何来自上述操作系统 CSS 规则的结果,则说明您没有使用 Mac OS X 10.5 或更早版本。(https://en.wikipedia.org/wiki/History_of_Firefox#Version_17_.28ESR.29)
相反地,在 Firefox 25+ 中可以否定 OS X (10.6 及更新版本) -- 因为 10.5 及更早版本不支持这个版本的 Firefox,这意味着它根本不是 Mac 系统。
@supports (-moz-appearance:none) and (background-attachment:local)
and (not (-moz-osx-font-smoothing:auto)) {
.nonmac {
color:red;
}
}
@supports (-moz-appearance:none) and (background-attachment:local)
and (not (-moz-osx-font-smoothing:auto)) {
@media not screen and (-moz-os-version) {
.lindroid {
color:red;
}
}
}
<!--[if (gte IE 6)&(lte IE 9)]><style type="text/css">
.windows {
color:red;
}
</style><![endif]-->
Internet Explorer 6只存在于Windows XP或早期的Windows版本中,这些版本已经不再使用,因此这个方法仅适用于该版本:
<!--[if (IE 6)]><style type="text/css">
.windows,.winxp {
color:red;
}
</style><![endif]-->
Internet Explorer 7存在于Windows XP和Vista中,并且在单击Internet Explorer 8或更新版本中的兼容性模式选项时通常会进行模拟。
如果您使用的是Internet Explorer 10或更新版本,则此选项适用,因此您需要Windows 7或8。
@media screen and (-ms-high-contrast:active), (-ms-high-contrast:none) {
.windows {
color:red;
}
}
我个人制作的一个程序可以检测Internet Explorer 11或更高版本,适用于Windows 7及以上版本,最高支持到8.1。
_:-ms-fullscreen, :root .windows {
color:red;
}
@media screen\9
{
.windows {
color:red;
}
}
@media screen and (min-width:0\0) and (min-resolution:.001dpcm)
{
.windows {
color:red;
}
}
@media \0screen
{
.windows {
color:red;
}
}
我从去年开始,从各种其他部分中制作了这个媒体查询,它可以处理Safari 6.1及更高版本。在发布此帖子时,Safari的版本为7。通过以下方式可以检测到Mac和移动设备,如基本的Android浏览器:
@media screen and (-webkit-min-device-pixel-ratio:0) and (min-color-index:0)
{
.mac_or_mobile {(;
color:red;
);}
}
@media screen and (-webkit-max-device-pixel-ratio:1) and (min-color-index:0)
{
.mac_osx {(;
color:red;
);}
}
@media screen and (-webkit-min-device-pixel-ratio:1.1) and (min-color-index:0)
{
.retina {(;
color:red;
);}
}
Per Firefox and Internet Explorer/Edge:
<div class="windows"> If this is Windows this is red </div>
<div class="winxp"> If this is Windows XP or older this is red </div>
<div class="win10"> If this is Windows 10 this is red </div>
Per Firefox:
<div class="vista"> If this is Windows Vista this is red </div>
<div class="win7"> If this is Windows 7 this is red </div>
<div class="win8"> If this is Windows 8 this is red </div>
<div class="nonwindows"> If this is NOT Windows this is red </div>
<div class="nonmac"> If this is NOT Mac OS X this is red </div>
<div class="mac"> If this is Mac OS X this is red </div>
<div class="mac10_7up"> If this is Mac OS X 10.7 or newer this is red </div>
<div class="mac10_6up"> If this is Mac OS X 10.6 or newer this is red </div>
<div class="mac10_6"> If this is Mac OS X 10.6 only this is red </div>
<div class="lindroid"> If this is Linux or Android this is red </div>
Per Safari:
<div class="mac_osx"> If this is a Mac using Safari
(desktop or laptop computer) this is red (includes old mobile devices but not before iOS 6) </div>
<div class="mac_or_mobile"> If this is a Mac or a mobile device using Safari
(Android or iPad/iPhone) this is red </div>
<div class="retina"> If this is a hi-def mobile device using Safari
(Android or iPad/iPhone) this is red </div>
关于检测的附加说明...
基于Internet Explorer/Edge的Windows版本(为方便起见):
As stated above if you detect Internet Explorer 6, you are using XP (or older Win)
If you detect Internet Explorer 7-8, you are using Windows XP, Vista, or Windows 7
If you detect Internet Explorer 9 you are using Windows Vista or Windows 7
If you detect Internet Explorer 10 you are using Windows 7 or Windows 8.0
If you detect Internet Explorer 11 you are using Windows 7 or Windows 8.0/8.1 or Windows 10
If you detect Microsoft Edge you are using Windows 10
在发布本文时,Windows 10是当前版本的Windows。
出于历史兴趣,如果你真的想要,你可以使用我发现的一个古老的黑客技巧在Mac上确定Internet Explorer 5或更低版本:
/*\*//*/ .mac_internet_explorer { color:red; } /**/
Internet Explorer 的 Mac 版本只能在旧的 PowerPC Mac 上使用,而不能在 Intel 版本上使用。