前端学习(五)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>
相关推荐
C语言小火车几秒前
野指针:C/C++内存管理的“幽灵陷阱”与系统化规避策略
c语言·c++·学习·指针
拾光拾趣录几秒前
深入解析 Vue.nextTick 源码:异步更新机制的核心实现
前端·vue.js
摆烂为不摆烂3 分钟前
😁深入JS(三): 一文让你完全了解原型,继承
前端
拾光拾趣录4 分钟前
在 Vue 中使用 SVG 图标
前端·vue.js·svg
吃饭睡觉打豆豆嘛4 分钟前
理解 react 中的受控组件和非受控组件
前端
默默地离开4 分钟前
Web APIs
前端·javascript
JarvanMo9 分钟前
用“工厂传送带”的方式理解 Dart/Flutter 事件循环
前端
Chef_Chen11 分钟前
从0开始学习R语言--Day40--Kruskal-Wallis检验
开发语言·学习·r语言
快乐非自愿19 分钟前
商品中心—库存分桶高并发的优化文档
java·前端·spring
灰海22 分钟前
原型与原型链到底是什么?
开发语言·前端·javascript·es6·原型模式·原生js