【慕课网】前端零基础入门---步骤二:页面化妆师CSS---06-CSS定位(position)

06-CSS定位(position)

第1章 position属性

1-1 position-static

在这里插入图片描述

1-2 position-relative

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

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		*{
			padding: 0;
			margin: 0;
		}
		.blue{
			width: 100px;
			height: 100px;
			background: blue;
			position: relative;
			top: 50px;
			left: 50px;
		}
		.red{
			width: 100px;
			height: 100px;
			background: red;
		}
	</style>
</head>
<body>
	<div class="blue"></div>
	<div class="red"></div>
</body>
</html>

1-3 position-absolute(实际工作用的最多,同时也相对比较难)


在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		.per{
			width: 300px;
			height: 300px;
			background: red;
			margin-left: 200px;
			margin-top: 200px;
		}
		.son{
			width: 100px;
			height: 100px;
			background: blue;
			position: relative;
			top: 100px;
			left: 100px;
		}
	</style>
</head>
<body>
	<div class="per">
		<div class="son"></div>
	</div>
</body>
</html>

1-4 position-fixed

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

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		.test{
			width: 800px;
			height: 100px;
			background: red;
			position: fixed;
			margin-left: -400px;
			top: 0;
			left: 50%;
		}
		.out{
			width: 100%;
			height: 2000px;
			background: #abcdef;
		}
	</style>
</head>
<body>
	<div class="out">
		<div class="test"></div>
	</div>
</body>
</html>



1-5 position-sticky(了解即可)

在这里插入图片描述

第2章 实际应用

在这里插入图片描述
效果图:
在这里插入图片描述
在这里插入图片描述

<!DOCTYPE html>
<html>
<head>
	<title>3</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		.page{
			width: 1400px;
			height: 800px;
			background: url(http://climg.mukewang.com/59c9f7ce0001839219034033.png) no-repeat center top;
		}
		.left{
			width: 210px;
			height: 250px;
			background: url(http://climg.mukewang.com/5a3383d00001a3dd02240364.png) no-repeat center top;
			position: fixed;
			left: 0;
			top: 50%;
			margin-top: -105px;
		}
		.right{
			width: 210px;
			height: 250px;
			background: url(http://climg.mukewang.com/5a3383c70001f1b702240364.png) no-repeat center top;
			position: fixed;
			right: 0;
			top: 50%;
			margin-top: -105px;
		}
	</style>
</head>
<body>
	<div class="page">
		<div class="left"></div>
		<div class="right"></div>
	</div>
</body>
</html>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值