当前位置:网站首页>Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
Positioning (relative positioning, absolute positioning, fixed positioning, Z-index) 2022-2-11
2022-07-03 03:17:00 【Try your best】
One 、 location
1.1 Relative positioning position: relative;
Relative to the original position , Make the specified offset , In terms of relative positioning , It's still in the standard document stream , The original position will be preserved
top:-20px;
left: 20px;
bottom: -10px;
right: 20px;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!-- Relative positioning
Offset from your original position
-->
<style>
body{
padding: 20px;
}
div{
margin: 10px;
padding: 5px;
font-size: 26px;
line-height: 100px;
}
#father{
border: 2px solid black;
padding: 0;
}
#first{
border: 1px solid #3a1fe8;
background: #a2bef3;
position: relative;
top:-20px;
left: 20px;
}
#second{
border: 1px dashed #c907ff;
background: #E0C3FC;
}
#third{
border: 1px dashed #fddc6c;
background: aqua;
position: relative;
bottom: -10px;
right: 20px;
}
</style>
</head>
<body>
<div id="father">
<div id="first"> The first box </div>
<div id="second"> The second box </div>
<div id="third"> The third box </div>
</div>
</body>
</html>

practice 
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> practice </title>
<style>
#dad{
width: 300px;
height: 300px;
border: 2px solid red;
padding: 10px;
}
a{
width: 100px;
height: 100px;
background: #ea77b0;
line-height: 100px;
text-align: center;
color: white;
text-decoration: none;
display: block;
}
a:hover{
background: #8EC5FC;
}
.a2,.a4{
position: relative;
left: 200px;
top: -100px;
}
.a5{
position: relative;
right: -100px;
bottom: 300px;
}
</style>
</head>
<body>
<div id="dad">
<a href="#" class="a1"> Link one </a>
<a href="#" class="a2"> Link 2 </a>
<a href="#" class="a3"> Link three </a>
<a href="#" class="a4"> Link four </a>
<a href="#" class="a5"> Link five </a>
</div>
</body>
</html>

1.2 Absolute positioning (position: absolute;)
location : be based on xxx location , The up and down or so
- Without parent element positioning , Relative to browser positioning
#second{
border: 1px dashed #c907ff;
background: #E0C3FC;
position: absolute;
right: 30px;
}
Absolute positioning is added after the second block , Is the distance for browsers 

- Suppose the parent element has a location , We usually offset relative to the parent element
The parent add
position: relative;
#second{
border: 1px dashed #c907ff;
background: #E0C3FC;
position: absolute;
right: 30px;
}

3、 Move within the scope of the parent element
Location relative to the parent or browser , Make the specified offset , If you're absolutely positioned , It's not in the standard document stream , The original position will not be preserved
1.3 Fixed position (position: fixed;)
Example : Comparison between absolute positioning and fixed positioning
fixed, Fixed position
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Fixed position </title>
<style>
body{
height: 1000px;
}
div:nth-of-type(1){/* Absolute positioning , Relative to the browser */
width: 100px;
height: 100px;
background: #8EC5FC;
position: absolute;
right: 0;
bottom: 0;
}
div:nth-of-type(2){/*fixed, Fixed position */
width: 50px;
height: 50px;
background: #fddc6c;
position: fixed;
}
</style>
</head>
<body>
<div>div1</div>
<div>div2</div>
</body>
</html>


Two 、z-index
Hierarchical concept 
2.1 Put the text on the top z-index: 999;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>zindex</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div id="context">
<ul>
<li><img src="image/1.jpg" alt=""></li>
<li class="tipText"> Early learning </li>
<li class="tipbg"></li>
<li> Time :2025-1-2</li>
<li> place : The earth </li>
</ul>
</div>
</body>
</html>
#context{
width: 400px;
padding: 0px;
margin: 0px;
overflow: hidden;
font-size: 12px;
line-height: 25px;
border: 1px solid #090909;
}
ul,li{
padding: 0;
margin: 0;
list-style: none;
}
#content ul{
position: absolute;
}
.tipText,.tipbg{
position: absolute;
width: 400px;
height: 25px;
top:384px;
}
.tipText{
color: white;
z-index: 999;/* Put the text on the top */
}
2.2 Background transparency (opacity: 0.5; or filter: alpha(opacity=1); All possible )
.tipbg{
background: #090909;
opacity: 0.5;/* Background transparency */
/*filter: alpha(opacity=1);*/ /* ditto , Background transparency */
}
边栏推荐
- MySQL practice 45 [SQL query and update execution process]
- 基于Qt的yolov5工程
- 模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
- How to limit the size of the dictionary- How to limit the size of a dictionary?
- Gavin teacher's perception of transformer live class - rasa project's actual banking financial BOT Intelligent Business Dialogue robot architecture, process and phenomenon decryption through rasa inte
- MySql实战45讲【索引】
- VS克隆时显示403错误
- The calculation of stripe, kernel and padding in CNN
- Bigvision code
- 二维数组中的元素求其存储地址
猜你喜欢

Pytorch轻量级可视化工具wandb(local)

Vs Code configure virtual environment

力扣------网格中的最小路径代价

Pytorch配置

分布式事务

MySql实战45讲【SQL查询和更新执行流程】

TCP handshake three times and wave four times. Why does TCP need handshake three times and wave four times? TCP connection establishes a failure processing mechanism
![MySQL practice 45 [SQL query and update execution process]](/img/cd/3a635f0c3bb4ac3c8241cb77285cc8.png)
MySQL practice 45 [SQL query and update execution process]

Installation and use of memory leak tool VLD

MySql实战45讲【全局锁和表锁】
随机推荐
使用InputFilter限制EditText时踩坑及解决方案
Limit of one question per day
Idea set method call ignore case
I2C subsystem (II): I3C spec
VS 2019 配置tensorRT生成engine
I2C 子系统(一):I2C spec
Why does thread crash not cause JVM crash
Can I use read-only to automatically implement properties- Is read-only auto-implemented property possible?
【AI实战】应用xgboost.XGBRegressor搭建空气质量预测模型(一)
Do you really understand relays?
模糊查詢時報錯Parameter index out of range (1 > number of parameters, which is 0)
I2C subsystem (IV): I2C debug
C# WebRequest POST模式 ,基于“Basic Auth”口令认证模式,使用multipart/form-data方式上传文件及提交其他数据
Elsevier latex 提交文章 pdftex.def Error: File `thumbnails/cas-email.jpeg‘ not found: using draf
How to make backgroundworker return an object
敏捷认证(Professional Scrum Master)模拟练习题
Force deduction ----- the minimum path cost in the grid
Pytoch configuration
二维数组中的元素求其存储地址
Bigvision code