前端学习之旅(四)【float实操】

任务

使用float的方式,实现以下效果:

代码实现

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <title>浮动小实践</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .horizontal {
            text-align: center;
        }

        .float-left {
            float: left;
        }

        .float-right {
            float: right;
        }

        .float-clear::after {
            content: "";
            display: block;
            clear: both;
        }

        .logo {
            width: 200px;
            margin-right: 10px;
        }

        .banner1 {
            width: 540px;
            margin-right: 10px;
        }

        .banner2 {
            width: 200px;
        }

        .logo,
        .banner1,
        .banner2 {
            height: 80px;
            line-height: 80px;
            background-color: #ccc;
        }

        .container {
            width: 960px;
            margin: 0 auto;
        }

        .menu {
            height: 30px;
            width: 960px;
            background-color: #ccc;
            line-height: 30px;
            margin-top: 10px;
        }

        .top-part {
            height: 198px;
            width: 368px;
            margin-right: 10px;
        }

        .content,
        .three,
        .four,
        .five,
        .six {
            margin-top: 10px;
        }

        .border1 {
            border: 1px solid black;
        }

        .bottom-part {
            height: 198px;
            width: 178px;
        }

        .margin-right-10 {
            margin-right: 10px;
        }

        .right-part {
            height: 128px;
            width: 198px;
        }

        .eight,
        .nine {
            margin-top: 10px;
        }

        .root {
            margin-top: 10px;
            height: 80px;
            width: 960px;
            background-color: #ccc;
            line-height: 80px;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header float-clear">
            <div class="logo horizontal float-left ">logo</div>
            <div class="banner1 horizontal float-left ">banner1</div>
            <div class="banner2 horizontal float-left">banner2</div>
        </div>

        <div class="menu horizontal">菜单</div>

        <div class="content float-clear">
            <div class="left float-left">
                <div class="top float-clear">
                    <div class="one top-part float-left horizontal border1">栏目一</div>
                    <div class="two top-part float-left horizontal border1">栏目二</div>
                </div>
                <div class="bottom float-clear">
                    <div class="horizontal three border1 bottom-part float-left margin-right-10">栏目三</div>
                    <div class="horizontal four border1 bottom-part float-left margin-right-10">栏目四</div>
                    <div class="horizontal five border1 bottom-part float-left margin-right-10">栏目五</div>
                    <div class="horizontal six border1 bottom-part float-left">栏目六</div>
                </div>
            </div>
            <div class="right float-right">
                <div class="right-part horizontal border1 seven">栏目七</div>
                <div class="right-part horizontal border1 eight">栏目八</div>
                <div class="right-part horizontal border1 nine">栏目九</div>
            </div>
        </div>

        <div class="root horizontal">页脚</div>
    </div>

</body>

</html>

实现结果展示

总结

在编写HTML页面元素之前,可以提前将一些大量使用的样式先制作对应的CSS样式,后续通过添加类名即可。

参考内容

浮动布局练习

  • 8
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值