HTML_position

position

positionfixedabsoluterelative
解释固定定位相对定位绝对定位
无父级释放了物理位置,保留空间位置,不会随着网页的滚动而滚动,悬浮在窗口上,位移的参考对象是body释放了物理位置,保留空间位置,随着网页的滚动而滚动,位移的参考对象是body,不会释放物理位置,位移的参考对象是本身的物理位置
有父级无定位释放掉自己的父级,位移的参考对象是body释放掉自己的父级,位移的参考对象是body不会释放掉自己的父级,位移的参考对象是本身的物理位置
有父级有定位同上不会释放掉自己的父级,位移的参考对象是自己的父级同上
应用悬浮广告,导航条解决网页中重叠的问题固定一个模块,作父级
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>position定位</title>
		<!--
			作者:shidiwen
			时间:2021-01-24
			描述:position
			position:定位
			fixed:固定定位,释放了物理位置,.在有父级(无论定位与否)的状态下,会释放掉自己的父级,保留空间位置,不会随着网页的滚动而滚动,悬浮在窗口上,位移的参考对象是body
			     top left right bottom:位移方向 可以是正数 表示正方向移动 负数 表示反方向移动
			absolute:相对定位,释放了物理位置,在有父级(无定位)的状态下,会释放掉自己的父级,保留空间位置,会随着网页的滚动而滚动,位移的参考对象是body,在父级(有定位)状态下,不会释放掉自己的父级,位移的参考对象是自己的父级
			relative:绝对定位,不会释放物理位置,在有父级(无论定位与否)的状态下,不会释放掉自己的父级,位移的参考对象是本身的物理位置
		-->
		<link rel="stylesheet" href="css/position.css" type="text/css">
	</head>
	<body>
		<div class="no1">
			<div class="n-n01"></div>
			<div class="n-n02"></div>
		</div>
		<div class="no2"></div>
		<div class="no3">
			<div class="n3-n01"></div>
			<div class="n3-n02"></div>
		</div>
	</body>
</html>
@charset "utf-8";
*{
	padding: 0px;
	margin: 0px;
}
.no1{
	width: 600px;
	height: 600px;
	background-color: red;
    /*position:fixed;*/
	/*top:100px;*/
	/*left:300px;*/
	/*left:-200px;*/
	/*float:left;*/
	/*position: absolute;*/
	/*top:200px;*/
	/*position: relative;*/
	/*top:300px;*/
}
.n-n01{
	width: 200px;
	height: 200px;
	background-color: burlywood;
	/*position: fixed;*/
	/*top:20px;*/
}
.n-n02{
	width: 400px;
	height: 400px;
	background-color: peachpuff;
}
.no2{
	width: 400px;
	height: 500px;
	background-color: yellow;
	/*position: fixed;*/
	/*top:10px;*/
	/*position: absolute;*/
	/*top:20px;*/
	/*position: relative;*/
	/*top:30px;*/
}
.no3{
	width: 600px;
	height: 1200px;
	background-color: deeppink;
	position: relative;
}
.n3-n01{
	width: 200px;
	height: 200px;
	background-color: green;
	/*position: fixed;*/
	/*top:30px;*/
	/*position:absolute;*/
	/*top:30px;*/
	/*position: relative;*/
	/*top:30px;*/
	/*position: fixed;*/
	/*top:20px;*/
	position: absolute;
	top:20px;
}
.n3-n02{
	width: 400px;
	height: 400px;
	background-color: skyblue;
}

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值