HTML的几种定位方式

定位

静态定位

static,默认

相对定位

relative
  • 参考物:定位前的位置
  • 特点
    –不影响元素本身特性
    – 元素不脱离文档流
    – 相对于原位置进行偏移

绝对定位

absolute
  • 参考物:最近的使用定位父级元素,如果没有,就找body
  • 特点
    –元素脱离文档流
    – 行元素支持所有css样式
    –块元素内容撑开宽高
    –清除子级浮动

固定定位

fixed
  • 参考物:浏览器窗口
  • 特点
    – 元素脱离文档流
    – 清除子级浮动

定位的作用

  • 可以使用便宜描述
  • 可以使用z-index提升层级
用定位实现哆啦A梦
<!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>哆啦A梦 头</title>
	<style>
		*{
			padding: 0;
			margin: 0;		
		}
		.ddm{
			width: 400px;
			height: 400px;
			background-color: pink;
			position: relative;
		}
		.ddm div{
			position: relative;
		}
		.hand{
			width: 380px;
			height: 350px;
			background-color: rgb(8, 178, 221);
			border: 1px solid #111;
			border-radius: 50%;
			top: 25px;
			left: 10px;
			filter: drop-shadow(-5px 10px 5px #6d6a6a);
		}
		.eye{
			height: 100px;
			width: 90px;
			border-radius: 45px;
			border: 3px solid #111;
			background-color: white;
			top: 48px;
			left: 100px;
			z-index: 1;
		}
		.eye1 div{
			width: 17px;
			height: 17px;
			background-color: #111;
			border-radius: 50%;
			left: 68px;
			top: 50px;
		}
		.eye2{
			left: 194px;
			top: -57px;
		}
		.eye2 div{
			width: 17px;
			height: 17px;
			background-color: #111;
			border-radius: 50%;
			left: 5px;
			top: 49px;
		}
		.head{
			width: 306px;
			height: 216px;
			background-color: white;
			border-radius: 103px;
			top: -100px;
			left: 38px;
		}
		.nose{
			width: 30px;
			height: 30px;
			background-color: rgb(204, 49, 4);
			border-radius: 15px;
			border: solid 2px #111;
			left: 138px;
			top: 20px;
			/* z-index: 1; */
		}
		.nose div{
			width: 12px;
			height: 12px;
			background-color: white;
			border-radius: 50%;
			left: 15px;
			top: 8px;
			filter:blur(3px) ;
		}
		.line{
			height: 132px;
			width: 3px;
			background-color: #111;
			left: 153px;
			top: 18px;
		}
		.mouse{
			width: 256px;
			height: 240px;
			background-color: transparent;
			border-radius: 120px;
			left: 25px;
			top: -226px;
			border-bottom: 4px solid#111;
		}
	</style>
</head>
<body>
	<div class="ddm">
		<div class="body">
			<div class="hand">
				<div class="eye eye1">
					<div></div>
				</div>
				<div class="eye eye2">
					<div></div>
				</div>
				<div class="head">
					<div class="nose">
						<div></div>
					</div>
					<div class="line"></div>
					<div class="mouse"></div>
				</div>
			</div>
		</div>
	</div>
	
</body>
</html>

12.jpg

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值