固定定位相对于当前父元素
生活随笔
收集整理的這篇文章主要介紹了
固定定位相对于当前父元素
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
我們知道,固定定位是相對(duì)于屏幕的。但是,怎么才能實(shí)現(xiàn)相對(duì)于當(dāng)前父元素呢?那就是不使用top left bottom right。而是使用margin-top margin-left margin-bottom margin-right
直接上代碼,測(cè)試一下,你會(huì)恍然大悟!
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>test</title><style>.father{top:100px;position: absolute;display: block;width: 200px;height: 200px;background: red;}.sun{position: fixed;margin-left: 100px;display: block;width: 100px;height: 100px;background:blue;}</style> </head> <body><div class="father"><div class="sun"></div></div> </body> </html>快去試試把~
總結(jié)
以上是生活随笔為你收集整理的固定定位相对于当前父元素的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【计算机毕业设计】课堂考勤微信小程序 基
- 下一篇: 产品logo的设计:图标与几何构成