【问题标题】:How do I style one HTML file with two CSS files?如何用两个 CSS 文件设置一个 HTML 文件的样式?
【发布时间】:2012-10-29 10:17:58
【问题描述】:

我必须创建两个版本的网络应用程序:一个用于横向,一个用于纵向。但我需要像我们通常在 iPad 中那样运行它们;在纵向模式下,纵向版本应该可以工作,如果模式是横向,那么横向版本。

如何用一个 HTML 文件和两个 CSS 文件制作网站?

【问题讨论】:

    标签: javascript html css responsive-design


    【解决方案1】:

    使用 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 */
    }
    

    【讨论】:

    • 这没问题,但是如何设置图像,如果我们有纵向模式图像尺寸小,横向野兔太大,那么如何解决这个问题
    【解决方案2】:

    研究响应式设计。 Twitter 的 Bootstrap 项目包括一系列响应式布局,但方法非常基本:根据设备的当前宽度定义 CSS。

    http://twitter.github.com/bootstrap/scaffolding.html#responsive

    这是一篇解释 CSS3 和媒体查询的文章:http://webdesignerwall.com/tutorials/responsive-design-with-css3-media-queries

    【讨论】:

    【解决方案3】:

    这里是标准设备的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 */
    }
    

    【讨论】:

      【解决方案4】:

      这个可以帮助你

      http://ajaxian.com/archives/iphone-windowonorientationchange-code

      它会检测浏览器的方向变化并调用 java Script 函数。在函数内部,您可以根据自己的喜好加载 css 类 :)

      【讨论】:

        猜你喜欢
        • 2010-09-27
        • 2013-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-07
        • 1970-01-01
        • 2012-12-13
        相关资源
        最近更新 更多