当前位置:网站首页>浮动效果与特点
浮动效果与特点
2022-07-19 05:21:00 【起ོ࿆始】
1.什么是浮动?
CSS 的 Float(浮动),会使元素向左或向右移动,其周围的元素也会重新排列。
Float(浮动),往往是用于图像,但它在布局时一样非常有用。
2.浮动的特点
特点1:
1:浮动元素会脱离文档流,元素脱离文档流以后,不会再占用文档流的位置,它下边的元素会立即向上移动
2:元素浮动以后,元素会尽量向页面的左上或页面右上漂浮
3:浮动元素默认不会从父元素中移出
4:浮动的元素不会超过他上边的兄弟元素,最多最多一边齐
5:如果浮动元素的上边是一个没有浮动的块元素,则浮动元素无法上移
特点2:
浮动的元素不会盖住文字,文字会自动环绕在浮动元素的周围,
所以我们可以通过浮动来设置文字环绕图片的效果
当元素设置浮动以后,会完全脱离文档流,元素的一些特点也会发生改变
3. 脱离文档流的特点
块元素:
1:块元素不再独占页面的一行
2:块元素的宽高被内容撑开
行内元素:
浮动过后的行内元素更像行内块元素,因问一行可以显示多个,并且默认宽度为内容的宽度
总结:当元素设置浮动以后,脱离文档流,就不需要再区分块和行内,更类似行内块元素
下面是用浮动做的简单的布局
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
li{
list-style: none;
}
a{
text-decoration: none;
}
body{
width: 900px;
margin: 0 auto;
/* 前提固定宽度 */
}
header{
width: 100%;
height: 100px;
background-color: aqua;
margin-bottom: 10px;
}
.div1{
width: 300px;
height: 300px;
background-color: aquamarine;
}
.div2{
width: 300px;
height: 300px;
background-color: black;
}
.div3{
width: 300px;
height: 300px;
background-color: rgb(235, 15, 198);
}
.div1,.div2,.div3,footer{
float: left;
}
footer{
width: 100%;
height: 300px;
background-color: rgb(176, 235, 15);
margin-top: 10px;
}
</style>
</head>
<body>
<header>
</header>
<main>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
</main>
<footer>
</footer>
</body>
边栏推荐
- 【report】tf-faster-rcnn 运行自己的训练数据 could not broadcast input array from shape (4) into shape (0)
- 在线问题反馈模块实战(七):安装部署swagger2
- Calculation process of pytorch gradient
- Qt5.12安装错误提示:C:\Qt5.12.11\vcredist\vcredist_msvc2019_x86.exe /norestart /q
- 【资源记录】如何用Pytorch的DataLoader加载自己的数据集
- 转:Pytorch模型小例子
- 论文笔记:Knowing When to Look: Adaptive Attention viaA Visual Sentinel for Image Captioning# Knowing Whe
- pytorch之nn.Conv1d详解
- ModuleNotFoundError: No module named 'gflags'
- vs2017 编译遇到COM 组件的调用返回了错误 HRESULT E_FAIL
猜你喜欢
Kubernetes command line management tool - kubectl
【资源记录】作为程序员 对统计学中的卡方分布/检测,t分布/检测,f分布/检测 的自学记录
Solution to unmount failure using umount command
DOM 事件对象
Qt5.12安装错误提示:C:\Qt5.12.11\vcredist\vcredist_msvc2019_x86.exe /norestart /q
FIO test hard disk performance
C语言基础知识
Examples of cat and dog classification -kaggle
Interpretation and practice of CEPH erasure code
Mocha测试
随机推荐
Qt5.12安装错误提示:C:\Qt5.12.11\vcredist\vcredist_msvc2019_x86.exe /norestart /q
转:Pytorch模型小例子
Insert cross column pictures under the title of the home page of latex IEEE paper, and solve the footnote problem
Solr搜索引擎 — 中文全拼简拼分词
Kubernetes命令行管理工具 — Kubectl
Alibaba cloud micro message queue mqtt
gocore-v2框架-API接口开发理念
Overview of key core technologies of intelligent operation and maintenance aiops worth seeing
websocket总结
JSON对象
Pytorch:visdom介紹
Go-Zero 业务开发军火库
Optimizer: torch optim
金仓数据库KingbaseES数据库管理员指南--13表的管理
lambda用法
CEPH detailed mon_ osd_ max_ split_ count
Pytoch:visdom introduction
Lunix boot and troubleshooting
Scala案例(伴生对象)
oracle 查询语句总结