前端学习(五)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>
相关推荐
talenteddriver11 分钟前
Java Web:http请求在springboot项目中的传递层级(自用笔记)
java·前端·spring boot·http
刘孬孬沉迷学习15 分钟前
层与天线的区别
网络·学习·5g·信息与通信·mimo·预编码·层映射
咘噜biu17 分钟前
Java后端和前端的接口数据加密方案(椭圆曲线集成加密方案)
java·前端·安全·aes·密钥协商ecdh·椭圆曲线集成加密方案
冬夜戏雪18 分钟前
【学习日记】【12.30】【14/60】
服务器·网络·学习
CodeSheep21 分钟前
百度又一知名产品,倒下了!
前端·后端·程序员
阿芯爱编程22 分钟前
前端面试题linux操作
前端·面试
Bug.ink37 分钟前
BUUCTF——WEB(4)
前端·网络安全·靶场·ctf·buuctf
L Jiawen38 分钟前
【Web】RESTful风格
前端·后端·restful
AI视觉网奇39 分钟前
火星- ue数字人智能体 学习笔记
人工智能·笔记·学习
深蓝海拓43 分钟前
PySide6从0开始学习的笔记(二十) qdarkstyle的深入应用
笔记·python·qt·学习·pyqt