国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > CSS > 正文

css position屬性為absolute時其百分值的計算

2024-07-11 09:00:10
字體:
來源:轉載
供稿:網友

當position為absolue時候,其相關屬性的百分比是相對它參考的元素(包含塊)來進行計算并進行位置渲染的 。

首先我們必須知道:

1、[百分比的參照][1]:

根據包含塊計算百分值(1)元素的margin/padding/left/right/width參照包含塊的width來計算;(2)要計算 height /top 及 bottom 中的百分值,是通過包含塊的 height 的值。如果包含塊的 height 值會根據它的內容變化,而且包含塊的 position 屬性的值被賦予 relative 或 static ,那么,這些值的計算值為 0。

2、[確定包含塊][2]:

確定一個元素的包含塊的過程完全依賴于這個元素的 position 屬性:

(1)如果 position 屬性為 static 或 relative ,包含塊就是由它的最近的“祖先塊元素”(比如說inline-block, block 或 list-item元素)或格式化上下文(比如說 a table container, flex container, grid container, or the block container itself)的內容區的邊緣(content)組成的。

(2)如果 position 屬性為 absolute ,包含塊就是由它的最近的 position 的值不是 static (也就是值為fixed, absolute, relative 或 sticky)祖先元素的內邊距區的邊緣(padding-left + content + padding-right)組成。

<!DOCTYPE html><html lang="en"><head>    <style>     body {  color: orange;}div {  position: absolute;   /*box-sizing: border-box; /*加box-sizing: border-box;時的content=(width-border-padding);未加時的width=content*/*/  width: 400px;  border: 5px solid orange;  padding: 50px;  height: 160px;  background: lightgray;}p {  position: absolute; /* 包含塊為最近的祖先元素(可能是塊也可能不是塊元素)的內邊距邊緣(padding-left + content + padding-right)組成;  width: 50%;   /* == (50+400+50)px * 50% = 250px */  height: 25%;  /* == (50+160+50)px * 25% = 65px */  margin: 5%;   /* == (50+400+50)px * 5% = 25px */  border: 5px solid orange;  padding: 5%;  /* == (50+400+50)px * 5% = 25px */  background: pink;  color: green;}/*p {   /* 包含塊為最近的祖先塊元素(只能是塊元素)或格式化上下文的內容區的邊緣(content)組成;  width: 50%;   /* == 400px * 50% = 200px */  height: 25%;  /* == 160px * 25% = 40px */  margin: 5%;   /* == 400px * 5% = 20px */  border: 5px solid orange;  padding: 5%;  /* == 400px * 5% = 20px */  background: pink;  color: green;}*/        </style></head><body>    <div>        <p>This is a paragraph!</p>    </div></body></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 华池县| 龙里县| 咸宁市| 宁波市| 舒城县| 垣曲县| 项城市| 富阳市| 绵竹市| 义乌市| 南阳市| 隆昌县| 丹巴县| 贺州市| 远安县| 兴安县| 金华市| 玛曲县| 鄄城县| 唐山市| 双峰县| 盐池县| 瑞昌市| 长子县| 澎湖县| 日照市| 五家渠市| 大悟县| 大竹县| 南充市| 丰顺县| 沅江市| 民县| 东乌珠穆沁旗| 察隅县| 龙陵县| 永寿县| 柯坪县| 绥化市| 清水河县| 邵武市|