【发布时间】:2012-10-29 10:17:58
【问题描述】:
我必须创建两个版本的网络应用程序:一个用于横向,一个用于纵向。但我需要像我们通常在 iPad 中那样运行它们;在纵向模式下,纵向版本应该可以工作,如果模式是横向,那么横向版本。
如何用一个 HTML 文件和两个 CSS 文件制作网站?
【问题讨论】:
标签: javascript html css responsive-design
我必须创建两个版本的网络应用程序:一个用于横向,一个用于纵向。但我需要像我们通常在 iPad 中那样运行它们;在纵向模式下,纵向版本应该可以工作,如果模式是横向,那么横向版本。
如何用一个 HTML 文件和两个 CSS 文件制作网站?
【问题讨论】:
标签: javascript html css responsive-design
使用 css3 媒体查询
/* 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 */
}
【讨论】:
研究响应式设计。 Twitter 的 Bootstrap 项目包括一系列响应式布局,但方法非常基本:根据设备的当前宽度定义 CSS。
http://twitter.github.com/bootstrap/scaffolding.html#responsive
这是一篇解释 CSS3 和媒体查询的文章:http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries
【讨论】:
这里是标准设备的css media queries:-
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen
and (min-width : 321px) {
/* Styles */
}
/* Smartphones (portrait) ----------- */
@media only screen
and (max-width : 320px) {
/* Styles */
}
/* 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 */
}
/* Desktops and laptops ----------- */
@media only screen
and (min-width : 1224px) {
/* Styles */
}
/* Large screens ----------- */
@media only screen
and (min-width : 1824px) {
/* Styles */
}
/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
【讨论】:
这个可以帮助你
http://ajaxian.com/archives/iphone-windowonorientationchange-code
它会检测浏览器的方向变化并调用 java Script 函数。在函数内部,您可以根据自己的喜好加载 css 类 :)
【讨论】: