响应式布局

2022/3/25 23:27:09

本文主要是介绍响应式布局,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

------------恢复内容开始------------

响应式布局就是手机端,电脑端,不管尺寸的大小,页面都能正常显示

 

------------恢复内容结束------------

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Media Queries</title>
    <style>
        body {
            font-family: Arial, Helvetica, sans-serif;
            background: gray;
            color: white;
            text-align: center;
            padding-top: 100px;
        }

        h1 {
            display: none;
        }

        /* samrtphone */
        /* 媒体查询 */
        @media(max-width:500px) {

            /* 当所用设备的宽超过500px样式不改变 当所用设备的宽不超过500px时 默认为手机端 */
            body {
                background: red;
            }

            #samrtphone h1 {
                display: block;
            }
        }

        /* table */
        /* 媒体查询 */
        @media (min-width: 501px) and (max-width:768px) {

            /* 当所用设备的宽超过500px样式不改变 当所用设备的宽不超过500px时 默认为手机端 */
            body {
                background: blue;
            }

            #table h1 {
                display: block;
            }
        }

        /* normal */
        /* 媒体查询 */
        @media (min-width: 769px) and (max-width:1200px) {

            /* 当所用设备的宽超过500px样式不改变 当所用设备的宽不超过500px时 默认为手机端 */
            body {
                background: greenyellow;
            }

            #normal h1 {
                display: block;
            }
        }

        /* widescreen */
        /* 媒体查询 */
        @media screen and (min-width: 1201px) {

            /* 当所用设备的宽超过500px样式不改变 当所用设备的宽不超过500px时 默认为手机端 */
            body {
                background: black;
            }

            #widescreen h1 {
                display: block;
            }
        }

        /* landscape */
        /* 媒体查询 */
        @media screen and (max-height: 500px) {

            /* 当所用设备的宽超过500px样式不改变 当所用设备的宽不超过500px时 默认为手机端 */
            body {
                background: orange;
            }

            #landscape h1 {
                display: block;
            }
        }
    </style>
    <link rel="stylesheet" media="screen and (max-width:768px;)" href="css/new_file.css">

</head>

<body>
    <div id="widescreen">
        <h1>Widescreen</h1>
    </div>
    <div id="normal">
        <h1>normal</h1>
    </div>
    <div id="table">
        <h1>Table</h1>
    </div>
    <div id="samrtphone">
        <h1>Samrtphone</h1>
    </div>
    <div id="landscape">
        <h1>Landscape</h1>
    </div>




</body>

</html>

  



这篇关于响应式布局的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程