網(wǎng)站首頁 編程語言 正文
1. 當(dāng)祖父元素是relative定位, 父元素是absolute定位, 子元素也是absolute定位
<script setup></script>
<template>
<div class="relative">
<p class="absolute1">absolute1
<p class="absolute2">absolute2</p>
</p>
</div>
</template>
<style scoped>
* {
margin: 0;
padding: 0;
}
.relative {
position: relative;
}
.absolute1 {
width: 100px;
height: 100px;
position: absolute;
left: 10px;
top: 10px;
background-color: blue;
}
.absolute2 {
width: 100px;
height: 100px;
position: absolute;
left: 10px;
top: 10px;
background-color: blueviolet;
}
</style>
最小輩分的元素的absolute定位是相對(duì)于離得最近的父輩元素偏移的, 如下圖所示:
如果absolute1是fixed定位呢?
<script setup></script>
<template>
<div class="relative">
<p class="absolute1">absolute1
<p class="absolute2">absolute2</p>
</p>
</div>
</template>
<style scoped>
* {
margin: 0;
padding: 0;
}
.relative {
position: relative;
}
.absolute1 {
width: 100px;
height: 100px;
position: fixed;
left: 10px;
top: 10px;
background-color: blue;
}
.absolute2 {
width: 100px;
height: 100px;
position: absolute;
left: 10px;
top: 10px;
background-color: blueviolet;
}
</style>
可以發(fā)現(xiàn)就算父輩元素absolute1是fixed定位, absolute2還是相對(duì)于最近的父輩元素absolute1相對(duì)偏移的如下圖所示:
試著把父輩元素absolute1改為inherit, static等其他position的值, absolute2還是相對(duì)于absolute1偏移的
2. 如果absolute1和absolute2是兄弟元素,
就是兄弟各自是各自的定位, 再往上找父輩元素相對(duì)偏移
<script setup></script>
<template>
<div class="relative">
<p class="absolute1">absolute1</p>
<p class="absolute2">absolute2</p>
</div>
</template>
<style scoped>
* {
margin: 0;
padding: 0;
}
.relative {
position: relative;
}
.absolute1 {
width: 100px;
height: 100px;
position: absolute;
left: 10px;
top: 10px;
background-color: blue;
}
.absolute2 {
width: 100px;
height: 100px;
position: absolute;
left: 10px;
top: 10px;
background-color: blueviolet;
}
</style>
如果left,top,bottom,right一樣,一般就重合了,后面的元素蓋住前面的元素如圖所示:
綜上所述: 有position: absolute定位的元素都是找最近的父輩元素(有position:xxx定位的)進(jìn)行相對(duì)偏移的
原文鏈接:https://blog.csdn.net/qq_42750608/article/details/133611890
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-11-06 Android?Navigation重建Fragment問題分析及解決_Android
- 2022-05-21 C#對(duì)DataTable中的某列進(jìn)行分組_C#教程
- 2022-04-20 Android實(shí)現(xiàn)環(huán)信修改頭像和昵稱_Android
- 2023-05-15 Android?onMeasure與onDraw及自定義屬性使用示例_Android
- 2022-10-30 Redis過期刪除策略與內(nèi)存淘汰策略_Redis
- 2022-08-06 Golang并發(fā)讀取文件數(shù)據(jù)并寫入數(shù)據(jù)庫的項(xiàng)目實(shí)踐_Golang
- 2022-11-30 CTF?AWD入門學(xué)習(xí)手冊(cè)_安全相關(guān)
- 2022-05-11 在?.NET?平臺(tái)使用?ReflectionDynamicObject?優(yōu)化反射調(diào)用的代碼詳解_實(shí)用
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支