gpt4 book ai didi

javascript - 动态 iPad & iPhone css 切换

转载 作者:行者123 更新时间:2023-11-28 13:17:14 24 4
gpt4 key购买 nike

我在使用 js 切换 ipad 和 iphone css 时遇到问题。

我目前正在设置什么时候

screen.width == 768, height == 481 // will switch to landscape.css 

screen.width == 481, height == 768 // will switch to portrait.css

<script type="text/javascript">
if ((screen.width == 640) && (screen.height == 480))
{document.write("<link href='640x480.css' rel='stylesheet' type='text/css'>")}

else if ((screen.width == 800) && (screen.height == 600))
{document.write("<link href='800x600.css' rel='stylesheet' type='text/css'>")}

else if ((screen.width == 1600) && (screen.height == 900))
{ document.write("<link href='main.css' rel='stylesheet' type='text/css'>")}

else if ((screen.width == 768) && (screen.height == 481))
{ document.write("<link href='landscape.css' rel='stylesheet' type='text/css'>")}

else if ((screen.width == 481) && (screen.height == 768))
{ document.write("<link href='portrait.css' rel='stylesheet' type='text/css'>")}

else
{document.write("<link href='main.css' 'type=text/css' rel='stylesheet' />")}
</script>

最佳答案

您可以在单个样式表中使用 CSS 媒体查询来实现此效果:

@media all and (max-width: 640px) {
/* relevant styles from 640x480.css */
}
@media all and (max-width: 768px) and (orientation: landscape) {
/* relevant styles from landscape.css */
}

关于javascript - 动态 iPad & iPhone css 切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14929514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com