1. 主页
  2. 文档
  3. CSS
  4. CSS3浮动定位与背景样式
  5. 使用浮动实现网页布局

使用浮动实现网页布局

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        header{
            width: 1000px;
            height: 100px;
            margin: 0 auto;
        }
        .content{
            width: 1000px;
            height: 500px;
            margin: 20px auto;
        }
        footer{
            width: 1000px;
            height: 100px;
            margin: 0px auto;
            background-color: #333;
        }
        header .logo{
            float: left;
            width: 220px;
            height: 100px;
            background-color: orange;
        }
        header .login{
            float: right;
            width: 220px;
            height: 30px;
            background-color: orange;
        }
        nav {
            float: right;
            width: 690px;
            height: 50px;
            margin-top: 20px;
            background-color: green;
        }
        .content .ad{
            float: left;
            width: 300px;
            height: 500px;
            background-color: rgb(9, 141, 182);
        }
        .content main{
            float: right;
            width: 680px;
            height: 500px;
        }
        .content main .banner {
            width: 680px;
            height: 380px;
            background-color: orange;
        }
        .content main .pics {
            width: 680px;
            height: 100px;
            margin-top: 20px;
        }
        .content main .pics ul {
            list-style: none;
        }
        .content main .pics ul li{
            float: left;
            width: 160px;
            height: 100px;
            background-color: blue;
            margin-right: 10px;
        }
        .content main .pics ul li:last-child {
            width: 170px;
            margin-right: 0;
        }
    </style>
</head>
<body>
    <header>
        <div class="logo"></div>
        <div class="login"></div>
        <nav></nav>
    </header>
    <section class="content">
        <aside class="ad"></aside>
        <main>
            <div class="banner"></div>
            <div class="pics">
                <ul>
                    <li></li>
                    <li></li>
                    <li></li>
                    <li></li>
                </ul>
            </div>
        </main>
    </section>
    <footer></footer>
</body>
</html>
这篇文章对您有用吗?

我们要如何帮助您?