前端入门笔记之css(8)
继承定位: 继承父级的定位。
父级是什么定位,它就是什么定位
{position:inherit;left:2000px;top:0;}
代码练习:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>继承定位</title>
<style type="text/css">
*{margin: 0;padding: 0;}
.div1{width: 200px;height: 200px;background: indianred;position: fixed;left: 0;top: 0;z-index: -1;}/*窗口定位*/
.div2{width: 100px;height: 100px;background: pink;position:inherit;left: 200px;top: 200px;float: left;}/*继承了父级的定位,也是窗口定位*/
.div3{width: 100px;height: 100px;background: blue;position: static;float: left;z-index: 1;}/*默认定位:就是没有定位*/
</style>
</head>
<body style="height: 3000px">
<div class="div1">
<div class="div2"></div>
<div class="div3"></div>
</div>
</body>
</html>
效果截图:
默认定位:就相当于没有定位。
注意:系统自带的,不需要去写。
{width: 100px;height: 100px;background: blue;position: static;float: left;;}