1、绝对定位的参考点---以页面的左上角或页面的左下角为参考点
绝对定位的参考点,如果用top描述,那么定位参考点就是页面的左上角,而不是浏览器的左上角:
代码如下:
<title>绝对定位的参考点---以页面的左上角或页面的左下角为参考点(重点)</title> <style> *{ margin: 0; padding: 0; } html,body{ width: 100%; height: 1600px; /* 渐变色的方向是从右向左 */ background-image: linear-gradient(to top, pink,orange, skyblue, green); } .box{ width: 200px; height: 200px; background-color:coral; /* 绝对定位 */ position: absolute; left: 100px; top: 20px; } </style> </head> <body> <div class="box"></div>
预览:
览: