前端学习(五)CSS浮动与补白

目录:

内容:

html 复制代码
//设置左右浮动
.left{
    float:left;
}
.right{
    float:right;
}
/*必须设置不同浮动*/
//创建div
<div>
<dic class="left">左边</div>
<div class="right">右边</div>
</div>
html 复制代码
//设置浮动
.left{
    width:50%;
    height:200px;
    background:pink;
    float:left;
}
.right{
    width:50%;
   height:200px;
   background:deepskyblue;
   float:right;
}
.center{
    width:100%;
    height:200px;
    background:orange;
//在被影响的标签里添加clear:both
    /* clear:both; */
}
.clear{
    clear:both;
}
//创建div
<div class="box">
    <div class="left">左边</div>
    <div class="right">右边</div>
    <div class="clear"></div>
    <div class="center"></div>
</div>
html 复制代码
//使用::after伪对象
.box::after{
    content:'';
    width:0;
    height:0;
    display:block;
    clear:both;
    visibility: hidden;
    overflow: hidden;
    zoom:1;
            } 
//设置浮动
.left{
    width:50%;
    height:200px;
    background:pink;
    float:left;
}
.right{
    width:50%;
   height:200px;
   background:deepskyblue;
   float:right;
}
.center{
    width:100%;
    height:200px;
    background:orange;
}
//创建div
<div class="box">
    <div class="left">左边</div>
    <div class="right">右边</div>
</div>
<div class="center"></div>
html 复制代码
//设置浮动
.left{
    width:50%;
    height:200px;
    background:pink;
    float:left;
}
.right{
    width:50%;
   height:200px;
   background:deepskyblue;
   float:right;
}
.center{
    width:100%;
    height:200px;
    background:orange;
//给被影响的元素添加overflow:hidden
    overflow:hidden;
}

//创建div
<div class="box">
    <div class="left">左边</div>
    <div class="right">右边</div>
    <div class="center"></div>
</div>
html 复制代码
.one{
    width:300px;
    height:300px;
    background:red;
    overflow:hidden;
}
.two{
    width:100px;
    height:100px;
   background:deepskyblue;
   margin-top:100px;
/* float:left; */
position:absolute;
}
//设置div
<div class="one">
    <div class="two"></div>
</div>
html 复制代码
.one{
    width:300px;
    height:300px;
    background:red;
}
.two{
    width:100px;
    height:100px;
   background:deepskyblue;
   margin-top:100px;
   float:left;
}
//设置div
<div class="one">
    <div class="two"></div>
</div>
html 复制代码
.one{
    width:300px;
    height:300px;
    background:red;
}
.two{
    width:100px;
    height:100px;
   background:deepskyblue;
   margin-top:100px;
   position:absolute;
}
//设置div
<div class="one">
    <div class="two"></div>
</div>
相关推荐
andrsted4 小时前
用练题簿小程序 - 让错题不再白错
学习·微信小程序·小程序·学习方法
2601_949950634 小时前
练题簿,把培训从“走过场”变成“真落地”
人工智能·学习·小程序·刷题·小程序推荐
问天_观心7 小时前
大模型微调学习(二)
人工智能·python·深度学习·学习·语言模型·transformer
梦曦i7 小时前
@meng-xi/create-uni-app vs unibest:轻量脚手架与重型框架的定位之争
前端·uni-app
指掀涛澜天下惊7 小时前
强化学习进阶篇八 策略梯度算法
深度学习·学习·算法·强化学习
平头哥技术团队7 小时前
Day 10 | 工欲善其事:VS Code 配置与项目归档
android·开发语言·前端·javascript·html·交互
star learning white7 小时前
STM32入门学习5
stm32·嵌入式硬件·学习
传奇开心果编程8 小时前
【Rust入门知识点学与练】第4课:条件判断 if / else
开发语言·学习·rust
乌恩大侠8 小时前
GH200 新增 NVMe SSD 分区、格式化与挂载完整流程
运维·服务器·前端
yume_sibai8 小时前
Element Plus 数据展示组件完全指南(15个核心组件)
前端·javascript·vue.js