前端学习(五)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>
相关推荐
风吹头皮凉11 分钟前
vue实现气泡词云图
前端·javascript·vue.js
南玖i12 分钟前
vue3 + ant 实现 tree默认展开,筛选对应数据打开,简单~直接cv
开发语言·前端·javascript
小钻风336633 分钟前
深入浅出掌握 Axios(持续更新)
前端·javascript·axios
萌萌哒草头将军41 分钟前
🚀🚀🚀尤雨溪推荐的这个库你一定要知道!轻量⚡️,优雅!
前端·vue.js·react.js
栗子不爱栗子41 分钟前
从理解AI到驾驭文字:一位技术爱好者的写作工具探索手记
python·学习·ai
三门1 小时前
docker安装mysql8.0.20过程
前端
BillKu2 小时前
Vue3 + Vite 中使用 Lodash-es 的防抖 debounce 详解
前端·javascript·vue.js
一只小风华~2 小时前
HTML前端开发:JavaScript的条分支语句if,Switch
前端·javascript·html5
橙子家2 小时前
Select 组件实现【全选】(基于 Element)
前端
超级土豆粉2 小时前
HTML 语义化
前端·html