如何在非移动设备上仅使用CSS类?

4

我需要一种方法,使CSS类仅适用于桌面(普通屏幕)。

例如:

.class {
  position: fixed;
}

仅适用于桌面设备。


请查看此条目https://dev59.com/MWw15IYBdhLWcg3wWqf-,在答案中您可以找到方法。 - Oldskultxo
1个回答

8
尽管它不是专门针对桌面的,但是您可以使用屏幕媒体规则来限制它在屏幕大小上的表现,像这样:
@media screen and (min-width: 640px) {
    .class {
        position: fixed;
    }
}

如果显示器的宽度至少为640像素,那么这将限制您的规则仅适用于大于智能手机(今天)的设备。


这也适用于JS。 var screenWidth = $( window ).width();if (screenWidth < 800) {你的代码} - damiano celent

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接