网站首页 > 技术文章 正文
一、position 属性
1、static:默认值,没有定位,以标准流方式显示。
2、relative:相对定位,相对于自身原来位置进行偏移。偏移设置:top、left、right、bottom;
设置相对定位的盒子会相对它原来的位置,通过指定偏移,到达新的位置。
设置相对定位的盒子仍在标准文档流中,它对父级盒子和相邻的盒子都没有任何影响。
设置相对定位的盒子原来的位置会被保留下来。
3、absolute:绝对定位 偏移设置: left、right、top、bottom;
使用了绝对定位的元素以它最近的一个“已经定位”的“祖先元素” 为基准进行偏移
如果没有已经定位的祖先元素,会以浏览器窗口为基准进行定位
绝对定位的元素从标准文档流中脱离,这意味着它们对其他元素的定位不会造成影响
元素位置发生偏移后,它原来的位置不会被保留下来
4、fixed:固定定位 偏移设置: left、right、top、bottom;
类似绝对定位,不过区别在于定位的基准不是祖先元素,而是浏览器窗口;
二、z-index属性:
调整元素定位时重叠层的上下位置
z-index属性值:整数,默认值为0
设置了positon属性时,z-index属性可以设置各元素之间的重叠高低关系
z-index值大的层位于其值小的层上方
属性说明举例
opacity:xx值为0~1,值越小越透明opacity:0.4;
filter:alpha(opacity=x)x值为0~100,值越小越透明filter:alpha(opacity=40);
三、代码展示:
<!DOCTYPE html>
<html lang="en">
<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>花样链接卡</title>
</head>
<style>
*{
padding:0px;
margin:0px;
}
a{
text-decoration: none;
color:#fff;
position: relative;
top:35px;
}
.container{
width:320px;
height: 320px;
margin-top: 10px;
margin-left: 10px;
border: 2px solid red;
}
.container>div{
display: block;
width: 100px;
height: 100px;
background:#fd7dfd;
text-align: center;
}
.container>div:nth-of-type(1){
position: relative;
left: 10px;
top:10px;
}
.container>div:nth-of-type(2){
position: relative;
left: 210px;
bottom: 100px;
top:-90px;
}
.container>div:nth-of-type(3){
position: relative;
left: 10px;
bottom:-10px;
}
.container>div:nth-of-type(4){
position: relative;
left: 210px;
bottom:90px;
}
.container>div:nth-of-type(5){
position: relative;
left: 110px;
bottom: 290px;
}
.container>div:hover{
background-color:blue;
}
</style>
<body>
<div class="container">
<div><a href="#">链接1</a></div>
<div><a href="#">链接2</a></div>
<div><a href="#">链接3</a></div>
<div><a href="#">链接4</a></div>
<div><a href="#">链接5</a></div>
</div>
</body>
</html>
<html>
<head>
<title>奖多多安全购彩页面</title>
</head>
<style>
.zhu{
width: 1300px;
margin-left: 250px;
}
.fu>.zuo{
position: absolute;
top:150px;
}
.fu .youOne{
position: absolute;
float:right;
top:150px;
right: 0px;
}
.fu .youTwo{
position: fixed;
float:right;
right: 0;
bottom: 220px;
}
.fu .youThree{
position: fixed;
float:right;
right: 0;
bottom: 0px;
}
</style>
<body>
<div class="container">
<div class="zhu">
<img src="img/1.bmp">
</div>
<div class="fu">
<div class="zuo">
<img src="img/2.bmp">
</div>
<div class="youOne">
<img src="img/3.bmp">
</div>
<div class="youTwo">
<img src="img/4.bmp">
</div>
<div class="youThree">
<img src="img/5.bmp">
</div>
</div>
</div>
</body>
</html>
效果图链接:file:///D:/ruanjian/VS/wenjianxiangmu/htmlEight/huayanglianjie.html
file:///D:/ruanjian/VS/wenjianxiangmu/htmlEight/caipiao.html
猜你喜欢
- 2024-09-12 5.标准文档结构(文档结构是什么)
- 2024-09-12 HTML5常用的标签 |实用干货(html5常用标签大全)
- 2024-09-12 5、标签分类和元素转换(标签元素是什么)
- 2024-09-12 「HTML二」 html常用标签(html常用标签有哪些)
- 2024-09-12 肖sir_html之A链接标签认识(2)(链接标签href属性可以指向)
- 2024-09-12 Foundation 提醒框(提示框怎么设置)
- 2024-09-12 HTML详细介绍1(“html”)
- 2024-09-12 HTML5新增了哪些结构标签?(html5新增结构化标签)
- 2024-09-12 全程软件测试(八十三):HTML语言基础知识必备—读书笔记
- 2024-09-12 页面中含有分享功能使用加注意事项
- 1512℃桌面软件开发新体验!用 Blazor Hybrid 打造简洁高效的视频处理工具
- 552℃Dify工具使用全场景:dify-sandbox沙盒的原理(源码篇·第2期)
- 503℃MySQL service启动脚本浅析(r12笔记第59天)
- 481℃服务器异常重启,导致mysql启动失败,问题解决过程记录
- 479℃启用MySQL查询缓存(mysql8.0查询缓存)
- 459℃「赵强老师」MySQL的闪回(赵强iso是哪个大学毕业的)
- 439℃mysql服务怎么启动和关闭?(mysql服务怎么启动和关闭)
- 436℃MySQL server PID file could not be found!失败
- 最近发表
- 标签列表
-
- c++中::是什么意思 (83)
- 标签用于 (65)
- 主键只能有一个吗 (66)
- c#console.writeline不显示 (75)
- pythoncase语句 (81)
- es6includes (73)
- windowsscripthost (67)
- apt-getinstall-y (86)
- node_modules怎么生成 (76)
- chromepost (65)
- c++int转char (75)
- static函数和普通函数 (76)
- el-date-picker开始日期早于结束日期 (70)
- js判断是否是json字符串 (67)
- checkout-b (67)
- c语言min函数头文件 (68)
- localstorage.removeitem (74)
- vector线程安全吗 (70)
- & (66)
- java (73)
- js数组插入 (83)
- mac安装java (72)
- eacces (67)
- 查看mysql是否启动 (70)
- 无效的列索引 (74)