zoukankan      html  css  js  c++  java
  • CSS3 为不同媒介设置样式的方法(CSS3 Media Queries)(转)

    随着智能手机、平板电脑越来越流行,许多网站都开始考虑为这些移动设备开发一套专属布局和样式。幸好 CSS3 提供了针对不同设备的查询规则,让这一目的变得非常容易实现。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    <style type="text/css">
    /*
        说明:CSS3 为不同媒介设置样式的方式(CSS3 Media Queries)
        来源:http://www.stuffandnonsense.co.uk/blog/about/hardboiled_css3_media_queries/
        整理:CodeBit.cn [ http://www.codebit.cn ]
    */
     
    /* 智能手机 (纵向 和 横向) ----------- */
    @media only screen
    and (min-device-width : 320px)
    and (max-device-width : 480px) {
    /* Styles */
    }
     
    /* 智能手机 (横向) ----------- */
    @media only screen
    and (min-width : 321px) {
    /* Styles */
    }
     
    /* 智能手机 (纵向) ----------- */
    @media only screen
    and (max-width : 320px) {
    /* Styles */
    }
     
    /* iPad 系列 (纵向 和 横向) ----------- */
    @media only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px) {
    /* Styles */
    }
     
    /* iPad 系列 (横向) ----------- */
    @media only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)
    and (orientation : landscape) {
    /* Styles */
    }
     
    /* iPad 系列 (纵向) ----------- */
    @media only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)
    and (orientation : portrait) {
    /* Styles */
    }
     
    /* 台式机 和 笔记本 ----------- */
    @media only screen
    and (min-width : 1224px) {
    /* Styles */
    }
     
    /* 大屏幕 ----------- */
    @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 */
    }
    </style>

    当然,将所有样式放在一起不是一个好主意,你可以将不同设备特定的 CSS 放到不同文件中,然后再通过 link 节点的 media 属性来加载:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <head>
     
    <link rel="stylesheet" href="smartphone.css"
    media="only screen and (min-device-width : 320px)
    and (max-device-width : 480px)">
     
    <link rel="stylesheet" href="smartphone-landscape.css"
    media="only screen and (min-width : 321px)">
     
    <link rel="stylesheet" href="smartphone-portrait.css"
    media="only screen and (max-width : 320px)">
     
    <link rel="stylesheet" href="ipad.css"
    media="only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)">
     
    <link rel="stylesheet" href="ipad-landscape.css"
    media="only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)
    and (orientation : landscape)">
     
    <link rel="stylesheet" href="ipad-portrait.css"
    media="only screen
    and (min-device-width : 768px)
    and (max-device-width : 1024px)
    and (orientation : portrait)">
     
    <link rel="stylesheet" href="widescreen.css"
    media="only screen and (min-width : 1824px)">
     
    <link rel="stylesheet" href="iphone4.css"
    media="only screen
    and (-webkit-min-device-pixel-ratio : 1.5),
    only screen and (min-device-pixel-ratio : 1.5)">
     
    </head>
    转自:http://www.codebit.cn/css/css3-media-queries.html
  • 相关阅读:
    微软ReportViewer(rdlc)发布时所需要的动态库(vs2010)
    Jquery插件easyUI属性汇总
    利用ymPrompt的doHandler方法来实现获取子窗口返回值
    解决弹出的窗口window.open会被浏览器阻止的问题(自定义open方法)
    window.showModalDialog 内跳转页面的问题
    jquery中的ajax调用.net的ashx文件
    在RDLC报表中添加链接
    医学图像分析顶级会议
    人脑是如何认知图像的?
    【转】Mean Shift Code for the Edge Detection and Image SegmentatiON system
  • 原文地址:https://www.cnblogs.com/2boy/p/3311921.html
Copyright © 2011-2022 走看看