<!doctype html><html lang="en"><head> <meta charset="utf-8"> <title>document</title> <style> *{ margin:0; padding:0; } .parent{ background: red; position: absolute; left:60px; width: 300px; height: 300px; } .childright{ background: blue; width: 240px; position: relative; right:60px; } .child-right{ background: yellow; width: 240px; position: relative; right:-60px; } .childleft{ background: blue; width: 240px; position: relative; left:60px; } .child-left{ background: yellow; width: 240px; position: relative; left:-60px; } </style></head><body> <div class="parent">parent <div class="childright">childright</div> <div class="child-right">child-right</div> <div class-"childleft">childleft</div> <div class="child-left">child-left</div> </div> <div style="width:300px;height:300px;border:1px solid #000">hello</div></body></html>
对,
相对定位情况下,是以元素自身原本的位置进行偏移,右边偏移正60px就等于左边偏移负60px。
为什么不显示颜色
这么明显,等于号你打成减号了
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号