【问题标题】:Can you have 1 layout for mobiles and another for tablets with jQuery mobile?您可以使用 jQuery mobile 为手机提供一种布局,而为平板电脑提供另一种布局吗?
【发布时间】:2014-06-21 14:35:20
【问题描述】:

我正在使用 jQuery mobile 开发一个应用程序,我想要 2 种设计/布局,一种用于移动设备,另一种用于平板电脑。那可能吗?如果是这样怎么办?是代码吗?

谢谢! 诺亚

【问题讨论】:

  • 您只需使用 CSS 媒体查询,完全独立于 jQuery 库。
  • 谢谢!我该怎么办?
  • 我会把它放在答案中

标签: html jquery-mobile mobile tablet


【解决方案1】:

扩展我上面的评论,您只需使用媒体查询设置您的 CSS 文件,以根据浏览器窗口大小更改布局。媒体查询如下所示:

/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
    **PUT YOUR MOBILE STYLES HERE**
}

/* Tablets (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
    **PUT YOUR TABLET STYLES HERE**
}

您可以根据需要更改最小/最大宽度。

假设您有一个类为donate 的按钮。在移动设备上,您希望按钮跨越包含 div 宽度的 100%,但在平板电脑上,您希望它设置为 300px 的宽度。这是您设置媒体查询的方式:

/* Smartphones (portrait and landscape) ----------- */
@media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
    .donate {
       width:100%;
    }
}

/* Tablets (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
    .donate {
       width:300px;
    }
}

【讨论】:

  • 好的,谢谢!所以我应该把它放在一个单独的 css 文件中并将其链接到 html 页面?
  • 它可以在您的主 CSS 文件中,但通常最好将其放在单独的文件中,这样您就可以将媒体查询与全局样式分开。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多