如何制作大小视口显示不同的网页

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>page layout ex</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<body>
<div id="container">
    <div id="header">
        <h1>g4lax's coffee hourse</h1>
    </div>

    <div id="main">

        <div class="sidebar">
            <ul>
                <li><a href="">Home</a></li>
                <li><a href="">Menu</a></li>
                <li><a href="">Music</a></li>
                <li><a href="">Jobs</a></li>
            </ul>
        </div>


        <div class="mainbar">
            <p id="welcome">Come in and experiences</p><br/>
            <ul>
                <li>Special coffee and tea</li>
                <li>Freshly made sandwiches</li>
                <li>Bagels Muffins,and Organic Snacks</li>
                <li>Music and Poetry Readings</li>
                <li>Open mid nights</li>
                <li>...</li>
            </ul><br/>



            <img src="img/1.png" width="200" height="175" alt="coffee">
            <div class="information">
                <p>23 Pine Road</p>
                <p>Nottingham,NGl5Yu</p>
                <p>1515 484544544</p>
            </div>

        </div>
    </div>
    <div id="footer">
        <p>copyright&copy;197xxxxx@qq.com</p>
        <p><a href="#">g4lax@nocoffee.com</a></p>
    </div>
</div>
</body>
</html>

```html

```css
*{
    margin: 0;
}

/*约束链接文字的点击前样式*/
a{
    color: #0000FF;
    text-decoration: none;
}

/*约束链接文字点击后样式*/
a:active {
    text-decoration: none;
    color: #006600;
}

body {
    color: #330000;
    background-color: #ffffcc;
}




#footer {
    clear: both;
    text-align: center;
    border-top: 1px solid #000;
}



#header {
    text-align: center;
    border-bottom: 1px solid #000;

}

#header, #footer {
    background: #ccaa66;
}

#header h1 {
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}


#container {
    width: 70%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translateX(-50%) translateY(-50%);
    border: 1px solid #000;
}


/* 大视口 */
@media all and (min-width: 768px) {
#header,#footer{
    height: 100px;
}

    .sidebar{
        width: 23%;
    }

    #main {
        background: #E8D882;
        overflow: hidden;
    }

    .mainbar p {
        position: relative;
        transform: translateX(3%) translateY(220%);
    }
    .mainbar {
        background: #f1e8b0;
        width: 76%;
        float: right;
        border-left: 1px solid #000;

    }
    .mainbar img {
        width: 30%;
        float: right;
        position: relative;
        left: -100px;
        top: -150px;
        transform: translateY(40%);
    }
    a {
        text-decoration: none;
    }

    #footer p {
        position: relative;
        top: 50%;
        transform: translateY(-130%);
        padding-top: 1%;
    }

    .mainbar ul {
        position: relative;
        transform: translateX(7%) translateY(40%);
        list-style: unset;
    }

    .information{
        margin-top: -2%;
    }
    .information p{
        line-height:2em;
    }

    .sidebar ul {
        position: relative;
        list-style: none;
        transform: translateX(25%) translateY(4%);
    }

    .sidebar ul li {
        line-height: 150%;
        padding-top: 10px;
    }

    .sidebar {
        background: #E8D882;
        float: left;
    }

}




/* 小视口 */
@media all and (max-width: 768px){

    #main{
        display: flex;
        flex-direction: column;
        align-items: center;
        flex-wrap:wrap;
    }

    #header,#footer{
        height: 75px;
    }
    .mainbar{
        display: flex;
        flex-direction: column;
        align-items: center;
        flex-wrap:wrap;
    }
    img{
        max-width: 100%;
        max-height: 100%;
        width: 70%;
        order:-1;
        margin-top: 2em;
    }

   #welcome{
       padding-top: 3em;
       margin-right: 9em;
   }

    .sidebar{
       width: 100%;
        order:22;
    }

    .information{
        margin-top: -10%;
        padding-top: 3em;
        margin-right: 12em;
    }

    .information p{
        line-height:2em;
    }

    #footer p {
        position: relative;
        top: 50%;
        transform: translateY(-130%);
        padding-top: 1%;
    }

    .mainbar ul {
        list-style: unset;
        margin-left: 1em;
    }

    .sidebar{
        background: #E8D882;
    }

    .sidebar ul {
        position: relative;
        list-style: none;
        transform: translateX(13%) translateY(-3%);
    }

    .sidebar ul li {
        line-height: 130%;
        padding-top: 10px;
    }


}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值