且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

& quot;显示完整网站& quot;按钮绕过CSS媒体查询

更新时间:2022-05-14 08:52:27

此方法有点多余,但是选择器具有更高的特异性,即使媒体查询匹配,选择器的属性也具有优先级.例如:

There is a bit of redundancy with this method, but a selector has higher specificity its properties have precedence even if a media query matches. For example:

.container, .full-site.container {
    /* full site styles */
}
@media (max-width: 395px) {
    .container {
        /* mobile styles */
    }
}

点击完整站点时,添加 .full-site 类,即使在像素宽度为395的设备上,完整站点样式也将适用.

When full site is clicked, add the .full-site class and the full site styles will apply even on devices with a 395 pixel width.

http://jsfiddle.net/7ZW9y/