web-rem layout-introducing resource case exercises

Import resources.html:

<!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>Introducing resource practice</title>

    <style>

        /* When our screen is greater than or equal to 640px, we display 2 divs in one row*/

        /* When our screen is smaller than 640px, we let the div display a row */

        /* A suggestion: the best way for us to query media is from small to large */

    </style>

    <link rel="stylesheet" href="style320.css" media="screen and (min-width:320px)">

    <link rel="stylesheet" href="style640.css" media="screen and (min-width:640px)">

</head>

<body>

    <div>1</div>

    <div>2</div>

</body>

</html>

 style640.css:

div {

    float: left;

    width: 50%;

    height: 100px;

}

div:nth-child(1) {

    background-color: yellow;

}

div:nth-child(2) {

    background-color: green;

}

style320.css:

div {

    width: 100%;

    height: 100px;

}

div:nth-child(1) {

    background-color: yellow;

}

div:nth-child(2) {

    background-color: green;

}

 

running result:

Screen below 640px:

 

Screen 640px and above:

 

Guess you like

Origin blog.csdn.net/m0_63171030/article/details/131374534