浮动练习(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>
相关推荐
布列瑟农的星空几秒前
webworker 实践:外部依赖引入和打包问题
前端·低代码
傻小胖3 分钟前
发布一个npm包,更新包,删除包
前端·npm·node.js
runnerdancer7 分钟前
解构shopify,从0到1实现落地页低代码编辑器
前端
WEI_Gaot26 分钟前
react19 的项目创建和组件使用
前端·react.js
资深前端外卖员30 分钟前
【nodejs高可用】前端APM应用监控方案 + 落地
前端·后端
OhBonsai30 分钟前
Shader 图像处理1_ToneMap技术处理过曝
前端
突头小恐龙30 分钟前
Chrome devTools - Lighthouse
前端·javascript·chrome
谦谦橘子30 分钟前
手写tiny webpack,理解webpack原理
前端·javascript·webpack
土豆125032 分钟前
Tailwind CSS 精通指南:提升效率、可维护性与最佳实践
前端·css
花生了什么树lll32 分钟前
面试中被问到过的前端八股(四)
前端·面试