浮动练习(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>
相关推荐
孤水寒月3 小时前
基于HTML的悬窗可拖动记事本
前端·css·html
祝余呀3 小时前
html初学者第一天
前端·html
耶啵奶膘6 小时前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
视频砖家6 小时前
移动端Html5播放器按钮变小的问题解决方法
前端·javascript·viewport功能
lyj1689976 小时前
vue-i18n+vscode+vue 多语言使用
前端·vue.js·vscode
小白变怪兽8 小时前
一、react18+项目初始化(vite)
前端·react.js
ai小鬼头8 小时前
AIStarter如何快速部署Stable Diffusion?**新手也能轻松上手的AI绘图
前端·后端·github
墨菲安全9 小时前
NPM组件 betsson 等窃取主机敏感信息
前端·npm·node.js·软件供应链安全·主机信息窃取·npm组件投毒
GISer_Jing9 小时前
Monorepo+Pnpm+Turborepo
前端·javascript·ecmascript
天涯学馆9 小时前
前端开发也能用 WebAssembly?这些场景超实用!
前端·javascript·面试