如何在iphone中将CSS纵向更改为横向?
我正在为移动设备制作一个网站。 在android和windows phone中,它正确加载两个方向。 在iPhone上,当您更改方向时,它不会加载新的css。 解决办法是什么 解决方案:如何在iphone中将CSS纵向更改为横向?,iphone,css,web,orientation,Iphone,Css,Web,Orientation,我正在为移动设备制作一个网站。 在android和windows phone中,它正确加载两个方向。 在iPhone上,当您更改方向时,它不会加载新的css。 解决办法是什么 解决方案: <script type="text/javascript"> function orient() { switch(window.orientation){ case 0: document.getElementById("orient_
<script type="text/javascript">
function orient()
{
switch(window.orientation){
case 0: document.getElementById("orient_css").href = "css/iphone_portrait.css";
break;
case -90: document.getElementById("orient_css").href = "css/iphone_landscape.css";
break;
case 90: document.getElementById("orient_css").href = "css/iphone_landscape.css";
break;
}
window.onload = orient();
函数定向()
{
开关(窗口方向){
案例0:document.getElementById(“orient_css”).href=“css/iphone_ratio.css”;
打破
案例-90:document.getElementById(“orient_css”).href=“css/iphone_scanner.css”;
打破
案例90:document.getElementById(“orient_css”).href=“css/iphone_scanner.css”;
打破
}
window.onload=orient();
实现此功能不需要JavaScript。使用CSS媒体查询:
@media only screen and (orientation : portrait) {
/* Portrait styles */
}
@media only screen and (orientation : landscape) {
/* Landscape styles */
}
或者,如果愿意,您可以为iPhone横向/纵向设置特定宽度
@media only screen and (min-width:320px) and (max-width:479px) {
/* Portrait styles */
}
@media only screen and (min-width:480px) {
/* Landscape styles */
}
Bens的答案是正确的。虽然这可能也适用于iPad,然后你可以像这样瞄准iPad
/* iPads (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px) {
/* Styles */
}
/* iPads (landscape) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : landscape) {
/* Styles */
}
/* iPads (portrait) ----------- */
@media only screen
and (min-device-width : 768px)
and (max-device-width : 1024px)
and (orientation : portrait) {
/* Styles */
}
您是否使用媒体查询来调整大小?Javascript?向我们显示您的代码,否则没有人可以帮助您