前端学习(五)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>
相关推荐
神之王楠8 分钟前
如何通过js加载css和html
javascript·css·html
余生H12 分钟前
前端的全栈混合之路Meteor篇:关于前后端分离及与各框架的对比
前端·javascript·node.js·全栈
Willliam_william15 分钟前
SystemC学习(1)— SystemC安装与HelloWorld
学习
程序员-珍15 分钟前
使用openapi生成前端请求文件报错 ‘Token “Integer“ does not exist.‘
java·前端·spring boot·后端·restful·个人开发
axihaihai20 分钟前
网站开发的发展(后端路由/前后端分离/前端路由)
前端
sealaugh3220 分钟前
aws(学习笔记第一课) AWS CLI,创建ec2 server以及drawio进行aws画图
笔记·学习·aws
布丁不叮早起枣祈20 分钟前
10.5学习
学习
向上的车轮29 分钟前
Django学习笔记五:templates使用详解
笔记·学习·django
流烟默32 分钟前
Vue中watch监听属性的一些应用总结
前端·javascript·vue.js·watch
2401_8572979142 分钟前
招联金融2025校招内推
java·前端·算法·金融·求职招聘