Sass 当切换到横向模式时,如何应用css规则?
我需要我的页面在不需要重新加载页面的情况下,为iPhoneX从纵向调整到横向 以下是我使用的媒体查询:Sass 当切换到横向模式时,如何应用css规则?,sass,media-queries,Sass,Media Queries,我需要我的页面在不需要重新加载页面的情况下,为iPhoneX从纵向调整到横向 以下是我使用的媒体查询: // Screen size variables $screen-sm-min: 576px; // Small tablets and large smartphones (landscape view) $screen-lg-min: 992px; // Tablets and small desktops //$screen-lg-min: 1024px; $screen-xl-m
// Screen size variables
$screen-sm-min: 576px; // Small tablets and large smartphones (landscape view)
$screen-lg-min: 992px; // Tablets and small desktops
//$screen-lg-min: 1024px;
$screen-xl-min: 1200px; // Large tablets and desktops
// Mixins
@mixin xs { @media (max-width: #{$screen-sm-min}),
(min-device-width : 375px) and (max-device-width : 667px),
(min-device-width : 414px) and (max-device-width : 736px),
(min-device-width : 375px) and (max-device-width : 812px) and (-webkit-device-pixel-ratio : 3)
{@content;} } // Tiny devices
@mixin md { @media (max-width: #{$screen-lg-min}), (min-device-width : 768px) and (max-device-width : 1024px),
(min-device-height : 1024px) and (max-device-width : 1366px)
{@content;} } // Medium devices
以下是该页面的链接:
我看过谷歌,但找不到这个问题的答案
感谢您的帮助CSS解决方案
您可以在媒体查询中使用
横向当浏览器窗口宽度大于高度时,规则适用:
@media (orientation: landscape) {
...
}
纵向当浏览器窗口高度大于宽度时,规则适用:
@media (orientation: portrait) {
...
}
JS解决方案()
注意:不幸的是,safari不支持此功能
当方向发生变化时,您可以收听orientationChange
事件,并在需要了解当前方向时阅读screen.orientation
screen.addEventListener("orientationchange", function () {
console.log("screen orientation: " + screen.orientation);
});
另一个选择是倾听窗口的大小调整,并比较宽度和高度的比率
如果(宽度/高度>1){//横向}其他{纵向}
我建议限制窗口大小侦听器。CSS解决方案
您可以在媒体查询中使用
横向当浏览器窗口宽度大于高度时,规则适用:
@media (orientation: landscape) {
...
}
纵向当浏览器窗口高度大于宽度时,规则适用:
@media (orientation: portrait) {
...
}
JS解决方案()
注意:不幸的是,safari不支持此功能
当方向发生变化时,您可以收听orientationChange
事件,并在需要了解当前方向时阅读screen.orientation
screen.addEventListener("orientationchange", function () {
console.log("screen orientation: " + screen.orientation);
});
另一个选择是倾听窗口的大小调整,并比较宽度和高度的比率
如果(宽度/高度>1){//横向}其他{纵向}
我建议限制窗口调整侦听器。我在body标记上放了一段javascript,这是根据windowWith调整正文宽度的,这是阻止在不重新加载页面的情况下进入横向模式的原因。我在body标记上放了一段javascript,这是根据windowWith调整主体宽度,这是阻止在不重新加载页面的情况下进入横向模式的原因。感谢您的响应,但添加这两个媒体查询不会改变任何事情,我需要css在更改为横向模式时进行调整,即我必须找到一种方法(可能使用Javascript?)为了检测横向模式被激活,然后刷新css,@learner我添加了几个JavaScript选项。我认为第一个没有safari支持yetThanks的响应,但是添加这两个媒体查询不会改变任何事情,我需要css在切换到横向模式时进行调整,即我必须找到一种方法(可能使用Javascript?)来检测横向模式被激活,然后刷新css,@我添加了一些JavaScript的可能性。我认为第一个还没有safari支持