各种设备的CSS3MediaQuery整理及爽歪歪写法

原文地址:http://sentsin.com/web/1134.html

  • 响应式布局

    响应式布局麻烦之处就是每个尺寸的都要进行css定义,这个真的不是一般的蛋疼,下面有搜集到的各种尺寸css Media Query内容,搜集来源:media-queries-for-standard-devices。

    看了之后是不是非常之蛋疼呢,那么只有使用工具来写这些玩意儿了,俺用得最爽的就是 stylus ,真的爽yy了,如果 stylus 不会玩耍请看这里 stylus入门使用方法

    stylus

                                // Media queries
    mq-mobile = "screen and (max-width: 479px)"
    mq-tablet = "screen and (min-width: 480px) and (max-width: 767px)"
    mq-iPhones4 = "only screen and (min-device-width: 320px) and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)"
    mq-normal = "screen and (min-width: 768px)"
    .page-number
        display: inline-block
        @media mq-mobile
            display: none
        @media mq-tablet
            color:red
        @media mq-iPhones4
            font-size:12px
        @media mq-normal
            background:yellow
                                
                               
                            

    代码laycode – v1.1

    编译成

                                .page-number {
      display: inline-block;
    }
    @media screen and (max-width: 479px) {
      .page-number {
        display: none;
      }
    }
    @media screen and (min-width: 480px) and (max-width: 767px) {
      .page-number {
        color: #f00;
      }
    }
    @media only screen and (min-device-width: 320px) and (max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {
      .page-number {
        font-size: 12px;
      }
    }
    @media screen and (min-width: 768px) {
      .page-number {
        background: #ff0;
      }
    }
                                
     
                            

    代码laycode – v1.1

    Phones and Handhelds

    iPhones

                                /* ----------- iPhone 4 and 4S ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 320px) 
      and (max-device-width: 480px)
      and (-webkit-min-device-pixel-ratio: 2) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 320px) 
      and (max-device-width: 480px)
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: portrait) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 320px) 
      and (max-device-width: 480px)
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: landscape) {
    }
    /* ----------- iPhone 5 and 5S ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 320px) 
      and (max-device-width: 568px)
      and (-webkit-min-device-pixel-ratio: 2) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 320px) 
      and (max-device-width: 568px)
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: portrait) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 320px) 
      and (max-device-width: 568px)
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: landscape) {
    }
    /* ----------- iPhone 6 ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 375px) 
      and (max-device-width: 667px) 
      and (-webkit-min-device-pixel-ratio: 2) { 
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 375px) 
      and (max-device-width: 667px) 
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: portrait) { 
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 375px) 
      and (max-device-width: 667px) 
      and (-webkit-min-device-pixel-ratio: 2)
      and (orientation: landscape) { 
    }
    /* ----------- iPhone 6+ ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 414px) 
      and (max-device-width: 736px) 
      and (-webkit-min-device-pixel-ratio: 3) { 
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 414px) 
      and (max-device-width: 736px) 
      and (-webkit-min-device-pixel-ratio: 3)
      and (orientation: portrait) { 
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 414px) 
      and (max-device-width: 736px) 
      and (-webkit-min-device-pixel-ratio: 3)
      and (orientation: landscape) { 
    }
                                
     
                            

    代码laycode – v1.1

    Galaxy Phones

                                /* ----------- Galaxy S3 ----------- */
    /* Portrait and Landscape */
    @media screen 
      and (device-width: 320px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 2) {
    }
    /* Portrait */
    @media screen 
      and (device-width: 320px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 2) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media screen 
      and (device-width: 320px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 2) 
      and (orientation: landscape) {
    }
    /* ----------- Galaxy S4 ----------- */
    /* Portrait and Landscape */
    @media screen 
      and (device-width: 320px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) {
    }
    /* Portrait */
    @media screen 
      and (device-width: 320px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media screen 
      and (device-width: 320px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) 
      and (orientation: landscape) {
    }
    /* ----------- Galaxy S5 ----------- */
    /* Portrait and Landscape */
    @media screen 
      and (device-width: 360px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) {
    }
    /* Portrait */
    @media screen 
      and (device-width: 360px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media screen 
      and (device-width: 360px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) 
      and (orientation: landscape) {
    }
                                
     
                            

    代码laycode – v1.1

    HTC Phones

                                /* ----------- HTC One ----------- */
    /* Portrait and Landscape */
    @media screen 
      and (device-width: 360px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) {
    }
    /* Portrait */
    @media screen 
      and (device-width: 360px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media screen 
      and (device-width: 360px) 
      and (device-height: 640px) 
      and (-webkit-device-pixel-ratio: 3) 
      and (orientation: landscape) {
    }
                                
         
                            

    代码laycode – v1.1

    Tablets

    iPads

                                /* ----------- iPad mini ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (-webkit-min-device-pixel-ratio: 1) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (orientation: portrait) 
      and (-webkit-min-device-pixel-ratio: 1) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (orientation: landscape) 
      and (-webkit-min-device-pixel-ratio: 1) {
    }
    /* ----------- iPad 1 and 2 ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (-webkit-min-device-pixel-ratio: 1) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (orientation: portrait) 
      and (-webkit-min-device-pixel-ratio: 1) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (orientation: landscape) 
      and (-webkit-min-device-pixel-ratio: 1) {
    }
    /* ----------- iPad 3 and 4 ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (-webkit-min-device-pixel-ratio: 2) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (orientation: portrait) 
      and (-webkit-min-device-pixel-ratio: 2) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 768px) 
      and (max-device-width: 1024px) 
      and (orientation: landscape) 
      and (-webkit-min-device-pixel-ratio: 2) {
    }
                                
                                
                            

    代码laycode – v1.1

    Galaxy Tablets

                                /* ----------- Galaxy Tab 10.1 ----------- */
    /* Portrait and Landscape */
    @media 
      (min-device-width: 800px) 
      and (max-device-width: 1280px) {
    }
    /* Portrait */
    @media 
      (max-device-width: 800px) 
      and (orientation: portrait) { 
    }
    /* Landscape */
    @media 
      (max-device-width: 1280px) 
      and (orientation: landscape) { 
    }
                                
                                
                            

    代码laycode – v1.1

    Nexus Tablets

                                /* ----------- Asus Nexus 7 ----------- */
    /* Portrait and Landscape */
    @media screen 
      and (device-width: 601px) 
      and (device-height: 906px) 
      and (-webkit-min-device-pixel-ratio: 1.331) 
      and (-webkit-max-device-pixel-ratio: 1.332) {
    }
    /* Portrait */
    @media screen 
      and (device-width: 601px) 
      and (device-height: 906px) 
      and (-webkit-min-device-pixel-ratio: 1.331) 
      and (-webkit-max-device-pixel-ratio: 1.332) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media screen 
      and (device-width: 601px) 
      and (device-height: 906px) 
      and (-webkit-min-device-pixel-ratio: 1.331) 
      and (-webkit-max-device-pixel-ratio: 1.332) 
      and (orientation: landscape) {
    }
                                
                                 
                            

    代码laycode – v1.1

    Kindle Fire

                                /* ----------- Kindle Fire HD 7" ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 800px) 
      and (max-device-width: 1280px) 
      and (-webkit-min-device-pixel-ratio: 1.5) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 800px) 
      and (max-device-width: 1280px) 
      and (-webkit-min-device-pixel-ratio: 1.5) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 800px) 
      and (max-device-width: 1280px) 
      and (-webkit-min-device-pixel-ratio: 1.5) 
      and (orientation: landscape) {
    }
    /* ----------- Kindle Fire HD 8.9" ----------- */
    /* Portrait and Landscape */
    @media only screen 
      and (min-device-width: 1200px) 
      and (max-device-width: 1600px) 
      and (-webkit-min-device-pixel-ratio: 1.5) {
    }
    /* Portrait */
    @media only screen 
      and (min-device-width: 1200px) 
      and (max-device-width: 1600px) 
      and (-webkit-min-device-pixel-ratio: 1.5) 
      and (orientation: portrait) {
    }
    /* Landscape */
    @media only screen 
      and (min-device-width: 1200px) 
      and (max-device-width: 1600px) 
      and (-webkit-min-device-pixel-ratio: 1.5) 
      and (orientation: landscape) {
    }
                                
                                 
                            

    代码laycode – v1.1

    Laptops

                                /* ----------- Non-Retina Screens ----------- */
    @media screen 
      and (min-device-width: 1200px) 
      and (max-device-width: 1600px) 
      and (-webkit-min-device-pixel-ratio: 1) { 
    }
    /* ----------- Retina Screens ----------- */
    @media screen 
      and (min-device-width: 1200px) 
      and (max-device-width: 1600px) 
      and (-webkit-min-device-pixel-ratio: 2)
      and (min-resolution: 192dpi) { 
    }
                                
                                
                            

    代码laycode – v1.1

    Wearables

    Apple Watch

                                /* ----------- Apple Watch ----------- */
    @media
      (max-device-width: 42mm)
      and (min-device-width: 38mm) { 
    }
                                
                                
                            

    代码laycode – v1.1

    Moto 360 Watch

                                /* ----------- Moto 360 Watch ----------- */
    @media 
      (max-device-width: 218px)
      and (max-device-height: 281px) { 
    }
                                
                                
                            

html中居中显示的几种方式

1. text-align: center; 水平居中
2. 设置line-height;垂直居中
3. display:table-cell;
   vertical-align:middle;
4.  display: flex;
     align-items: center;
     justify-content: center;
5.  背景图片居中 background: url('2.png') no-repeat 50% 50%/32px 32px;

源代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Center</title>
    <style>
        div {
            font-size: 12px;
            width: 100px;
            height: 100px;
            border: 1px solid red;
            margin-bottom: 5px;
        }

        img {width: 32px}

        .div1 {
            text-align: center;
        }

        .div2 {
            line-height: 100px;
        }

        .div3 {
            display:table-cell;
            vertical-align:middle;
        }

        .div4 {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .div5 {
           background: url('2.png') no-repeat 50% 50%/32px 32px;
        }

    </style>
</head>
<body>
    <div class="div1">文字水平居中</div>
    <h5>line-height</h5>
    <div class="div2">文字垂直居中</div>
    <div class="div2"><img src="2.png" alt=""></div>

    <h5>table-cell</h5>
    <div class="div3">文字垂直居中,这个更好些,内联元素</div>
    <div class="div3"><img src="2.png" alt=""></div>

    <h5>flex</h5>
    <div class="div4">
        flex布局垂直水平居中,下一个div换行显示。
    </div>
    <div class="div4">
        <img src="2.png" alt="">
    </div>
    <h5>background-image</h5>

    <div class="div5">

    </div>

</body>
</html>

演示地址:
http://xhope.top/samples/html/center_middle.html

html背景图的显示

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>background</title>
    <style>
        div {
            width: 200px;
            height: 200px;
            background: url('1.jpg') no-repeat scroll -10px -10px/100px 100px content-box padding-box yellow;

            /*拆分
                background-image:url(1.jpg);
                background-repeat:no-repeat;
                background-attachment:scroll;
                background-position:-10px -0px;
                background-size:100px 100px;
                background-origin:content-box;
                background-clip:padding-box; 从padding(不包括padding)往外裁剪
                background-color: yellow;
            */

            padding: 20px;
            border: 20px dashed red;
        }
    </style>
</head>
<body>
    <div>content</div>
</body>
</html>

演示地址

http://xhope.top/samples/html/background.html

html css中的position的运用

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>position</title>

    <style>

        .parent {
            position: relative;
            width: 210px;
            height: 250px;
            background-color: yellow
        }

        div {
            width: 200px;
            height: 200px;
        }

        #relative {
            background-color: red;
            position: absolute;
            left:10px;
            top:10px;
            z-index: 1;
        }

        .general {
            background-color: grey;
            width: 100%;
            height: 220px;
        }

        #absoulte {
           background-color: red;
           position: relative;
           left:10px;
           top:10px;
       } 
    </style>
</head>
<body>
    <div class="parent">
        <div id="relative">
            relative相对于自己原来的位置偏移 left:10px;top:10px;不占位
        </div>
        <div class="general"></div>
    </div>
    <hr>
     <div class="parent">
        <div id="absoulte">
            absoulte以父层做为定位基线的话,在父层应用absolute或relativ属性就可以,left:10px;top:10px;占位
        </div>
        <div class="general"></div>
    </div>

</body>
</html>

演示地址
http://xhope.top/samples/html/position.html

html viewport的学习

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1">
    <title>width</title>
    <style>
        body {
            padding:0;
            margin:0;
        }
        .container {
            margin: 0;
            padding: 0;
            background-color: red;
        }

       /*  @media all and (max-device-width: 320px) {
           .container {
               width: 100px;
           }
       } */
    </style>
</head>
<body>
    <div class="container" id="container">
        hello world
    </div>
    <script>
        alert("window.innerWidth = " + window.innerWidth);
        alert("screen.width = " + screen.width);
        alert("container = " + document.getElementById('container').clientWidth);
    </script>
</body>
</html>

演示地址
http://xhope.top/samples/html/viewport.html