固定定位相对于当前父元素
生活随笔
收集整理的這篇文章主要介紹了
固定定位相对于当前父元素
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我們知道,固定定位是相對于屏幕的。但是,怎么才能實現相對于當前父元素呢?那就是不使用top left bottom right。而是使用margin-top margin-left margin-bottom margin-right
直接上代碼,測試一下,你會恍然大悟!
<!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>快去試試把~
總結
以上是生活随笔為你收集整理的固定定位相对于当前父元素的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【计算机毕业设计】课堂考勤微信小程序 基
- 下一篇: 产品logo的设计:图标与几何构成