浮动模块布局

基本思路

若宽度和浏览器一样宽,则不需要设置width

一般父盒子使用标准流,然后标准流内使用浮动

一般父盒子需要居中显示,使用 margin: 0 auto;

注意浮动盒子之间的margin值 与 父盒子width、height值之间的相等关系,一定要计算好!

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>浮动布局</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
 
        .top {
            /* width和浏览器默认的一致,不用设置 */
            height: 50px;
            margin-top: 20px;
            background-color: pink;
        }
 
        .banner {
            height: 120px;
            width: 1010px;   /*设置快读*/
            margin: 10px auto;  /*居中*/
            background-color: green;
        }
 
        .box {
            height: 300px;
            width: 1010px;
            margin: 10px auto;
            background-color: lightblue;
        }
 
        .box>.box1 {
            float: left;
            margin: 10px;
        }
 
        .box>div {
            float: left;
            background-color: pink;
            margin: 10px;
            margin-left: 0;
            height: 280px;
            width: 240px;
        }
 
        .footer {
            height: 300px;
            background-color: aquamarine;
        }
    </style>
</head>
<body>
    <div class="top">top</div>
    <div class="banner">banner</div>
    <div class="box">
        <div class="box1">box1</div>
        <div class="box2">box2</div>
        <div class="box3">box3</div>
        <div class="box4">box4</div>
    </div>
    <div class="footer">footer</div>
</body>
</html>
相关推荐
sdgsdgdsgc20 小时前
Next.js企业级应用开发:SSR、ISR与性能监控方案
开发语言·前端·javascript
哲此一生98420 小时前
搭建Vue3工程(去除不必要的文件)
前端·javascript·vue.js
心止水j20 小时前
spark
javascript·数据库·spark
黑云压城After1 天前
H5使用环信实现视频或语音通话
前端·javascript·vue.js
未来之窗软件服务1 天前
自己写算法(九)网页数字动画函数——东方仙盟化神期
前端·javascript·算法·仙盟创梦ide·东方仙盟·东方仙盟算法
你的人类朋友1 天前
什么是断言?
前端·后端·安全
FIN66681 天前
昂瑞微:实现精准突破,攻坚射频“卡脖子”难题
前端·人工智能·安全·前端框架·信息与通信
椎4951 天前
苍穹外卖前端nginx错误之一解决
运维·前端·nginx
@。1241 天前
对于灰度发布(金丝雀发布)的了解
开发语言·前端
我有一棵树1 天前
前端图片加载失败、 img 出现裂图的原因全解析
前端