浮动练习(1)

复制代码
要求呈现图案:

法一:不建议
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title> </title>
        <style>
            div:nth-child(1){
                width: 100px;
                height: 100px;
                background-color: aqua ;
                float: left;
            }
            div:nth-child(2){
                width: 300px;
                height: 100px;
                background-color: purple ;
            
            }
            div:nth-child(3){
                width: 100px;
                height: 200px;
                background-color: gold ;
                float: left;
            }
            div:nth-child(4){
                width: 100px;
                height: 200px;
                background-color: red ;
                float: left;
            }
            div:nth-child(5){
                width: 300px;
                height: 100px;
                background-color: black ;
                
            }
            div:nth-child(6){
                width: 300px;
                height:100px;
                background-color: palegoldenrod ;
            
            }
        </style>
    </head>
    <body>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        
    </body>
</html>

法二:建议用此方法
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .container{
            width: 300px;
            height: 300px;
            background-color: gray;
            
        }
        .container .top{
            width: 300px;
            height: 100px;
            background-color: blue;
            
        }
        .container .bottom{
            width: 300px;
            height: 200px;
            background-color: purple;
            
            }
        .container .top .left{
            width: 100px;
            height: 100px;
            background-color: red;
            
        }
        .container .bottom .left{
            width: 100px;
            height: 200px;
            background-color: yellow;
            float: left;
        }
        .container .bottom .center{
            width: 100px;
            height: 200px;
            background-color: pink;
            float: left;
        }
        .container .bottom .right{
            width: 100px;
            height: 200px;
            background-color: green;
            float: left;
        }
        .container .bottom .right .top{
            width: 100px;
            height: 100px;
            background-color: gold;    
        }
        .container .bottom .right .bottom{
            width: 100px;
            height: 100px;
            background-color: greenyellow;

        }
            
        </style>
</head>
<body>
        <div class="container">
            <div class="top">
                <div class="left"></div>
            </div>
            <div class="bottom">
               <div class="left"></div>
               <div class="center"></div>
               <div class="right">
                 <div class="top"></div>
                   <div class="bottom"></div>
               </div>
            </div>            
        </div>
</body>
</html>
相关推荐
福兮说42 分钟前
纯前端把图片压缩到指定体积:canvas.toBlob 配合二分查找
前端·javascript·canvas·图片处理
是立不是利1 小时前
CSS 入门与进阶:从选择器到响应式布局的完整指南
前端·css
镭立智能制造1 小时前
电线电缆换线频繁?MES系统如何缩短换线时间40%
前端·制造
Amos_Web1 小时前
Rspack 源码解析(五):CodeGenerationPass 与模块代码生成
前端·前端框架·源码阅读
八荒启·交互动画1 小时前
Web特效06——WebGL深挖:顶点着色器和片元着色器到底在干什么
前端·网页特效·八荒启-交互动画·八荒启
这锅我不背哈2 小时前
前端权限控制实践:基于 RBAC 的完整落地方案
前端
星空2 小时前
Map<String, String>`Map`是接口,不能直接 new
java·前端·算法
开开心心就好2 小时前
低年级识字练笔顺工具,电脑和安卓端都能用
前端·javascript·网络·安全·scala·erlang·语音识别
杨利杰YJlio2 小时前
ITSK PE 26U5 测试版解读:组件完善、VMD 修复与服务器支持边界
前端·javascript·后端
志尊宝2 小时前
Vue3 零基础每日笔记(021):class 与 style 动态绑定——对象、数组、三元表达式写法汇总
前端·vue.js·笔记·前端框架·html5