我希望我的网站只能以横向模式显示,这是否可能?无论用户手中的设备方向如何,网站始终处于横向模式。我见过iPhone应用程序可以这样工作,但网站能否做到这一点?
我希望我的网站只能以横向模式显示,这是否可能?无论用户手中的设备方向如何,网站始终处于横向模式。我见过iPhone应用程序可以这样工作,但网站能否做到这一点?
<style type="text/css">
#warning-message { display: none; }
@media only screen and (orientation:portrait){
#wrapper { display:none; }
#warning-message { display:block; }
}
@media only screen and (orientation:landscape){
#warning-message { display:none; }
}
</style>
....
<div id="wrapper">
<!-- your html for your website -->
</div>
<div id="warning-message">
this website is only viewable in landscape mode
</div>
用户可以任意更改设备屏幕方向,但您至少可以向他们发送消息。此示例将在纵向模式下隐藏包装器并显示警告消息,然后在横向模式下隐藏警告消息并显示纵向模式。
我认为这个答案并没有比 @Golmaal 更好,只是对它的赞扬。如果您喜欢这个答案,请确保给 @Golmaal 认可。
更新
最近我一直在使用 Cordova,结果发现当您有访问本机功能的权限时,您可以控制它。
另一个更新
所以,在发布 Cordova 之后,最终效果真的很糟糕。如果您想要 JavaScript,最好使用类似于 React Native 的东西。它真的很棒,我知道它不是纯 web,但是移动端的纯 web 经验有些失败。
orientation
条件组属性的存在会更好。 - Vince虽然我自己会一直等待答案,但我想知道是否可以通过CSS实现:
@media only screen and (orientation:portrait){
#wrapper {width:1024px}
}
@media only screen and (orientation:landscape){
#wrapper {width:1024px}
}
试试这个,它可能更适合你
#container { display:block; }
@media only screen and (orientation:portrait){
#container {
height: 100vw;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
-ms-transform: rotate(90deg);
transform: rotate(90deg);
}
}
@media only screen and (orientation:landscape){
#container {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
transform: rotate(0deg);
}
}
<div id="container">
<!-- your html for your website -->
<H1>This text is always in Landscape Mode</H1>
</div>
这将自动管理甚至旋转。
html {
@media only screen and (orientation: portrait) and (max-width: 555px) {
transform: rotate(90deg);
width: calc(155%);
.content {
width: calc(155%);
}
}
}
这对我有用!
CSS:
.container {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: lightcyan;
}
@media screen and (min-width: 320px) and (max-width: 767px) and (orientation: portrait) {
.container {
transform: rotate(-90deg);
transform-origin: left top;
width: 100vh;
height: 100vw;
overflow-x: hidden;
position: absolute;
top: 100%;
left: 0;
}
}
HTML:
<div className="container">
{/* your code for your website */}
</div>