当前位置:网站首页>设置浮动无法浮动到上一个div的上面
设置浮动无法浮动到上一个div的上面
2022-07-21 18:09:00 【益达木咸醇】
今天又踩了一个坑,是我忘记了float样式的原本的效果了【哭】。
来看下代码:
html代码:
<body>
<div class="box1"></div>
<div class="box2">设置浮动只会影响后面元素的布局</div>
<div class="box3"></div>
</body>
css代码:
.box1{
width: 200px;
height: 200px;
background-color: red;
}
.box2{
width: 100px;
height: 100px;
border: 1px solid yellow;
}
.box3{
width: 200px;
height: 200px;
border: 1px solid black;
}
这里没有给.box2设置浮动,效果如下图:
重新设置.box2的样式:
.box2{
width: 100px;
height: 100px;
border: 1px solid yellow;
float: left;
}
效果:
可以看得出,float样式只会影响后面元素的布局,我之前做一个布局一直在想,我设置了float:left;为什么div浮动不上去呢,是我忘记了浮动的特性了,在此提醒自己,也希望有人看到这篇文章是能够解决您的疑惑。
边栏推荐
猜你喜欢
EAS BOS 报表开发
无套路、无陷阱、无广告 | 这个免费的即时通讯软件确定不用吗?
EAS Web BIM启动访问提示500错误
Performance optimization
Gluttonous snake
27.最长递增子序列
High frequency leetcode deep search part: Sword finger offer 36 Binary search tree and bidirectional linked list
window系统下使用nvm安装后node生效但是npm不生效
Gan objective function understanding
SwipeMenuRecyclerView 的用法
随机推荐
Biochemistry review II. Nucleic acid
Thunderbolt interview questions
refreshToken
动画移动的相关规律(根据参数判断到底移动到哪里去)
High frequency leetcode deep search part: Sword finger offer 13 Range of motion of robot
EAS web BIM start access prompt 500 error
关于包装对象
EAS 审批流相关表
鼓励企业知识共享的好处,你知道多少?
微信小程序width100%时padding或者border后导致超出边距的解决方案
Handler学习
第十题:在行和列都排好序的数组中找数
Permission
ConstraintLayout从0到0.n学习
微信小程序 不在以下 request 合法域名列表中
Three ways to turn the extra part of the text into an ellipsis
生物化学复习VII·糖代谢
数智融合加速驱动企业商业创新
Activity启动(launchActivity/startActivity)_(1)_流程图之WMS
微信小程序 Image 图片实现宽度100%,高度自适应