本篇內(nèi)容介紹了“HTML絕對定位的參考點(diǎn)及注意事項(xiàng)有哪些”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

專注于為中小企業(yè)提供成都網(wǎng)站制作、做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)全南免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千余家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
一、絕對定位參考點(diǎn)
1.規(guī)律:
(1)默認(rèn)情況下所有的絕對定位的元素,無論有沒有祖先元素,都會(huì)以body作為參考點(diǎn)。
<style>
.box1{
width: 300px;
height: 300px;
background-color: red;
/*position:absolute;*/
/*left:0px;*/
/*bottom:0px;*/
}
.box2{
width: 200px;
height: 200px;
background-color: yellow;
position: absolute;
left:0px;
bottom:0px;
}
</style>
</head>
<body>
<div class="box1">
<div class="box2"></div>
</div>(2)如果有一個(gè)絕對定位的元素有祖先元素,并且祖先元素也是定位流,那么這個(gè)絕對定位的元素就會(huì)以定位流的那個(gè)祖先元素為參考點(diǎn)。
.box1{
width: 300px;
height: 300px;
background-color: red;
position:absolute;
left:0px;
bottom:0px;
}
.box2{
width: 200px;
height: 200px;
background-color: yellow;
position: absolute;
left:0px;
top:0px;
}注意點(diǎn):i.只要是這個(gè)絕對定位元素的祖先元素都可以。ii.指的定位流是指絕對定位/相對定位/固定定位,定位流中只有靜態(tài)定位是不行的。
(3)如果一個(gè)絕對定位的元素有祖先元素,并且祖先元素也是定位流,而且祖先元素中有多個(gè)元素都是定位流,那么這個(gè)絕對定位的元素會(huì)以離它最近的祖先元素作為參考點(diǎn)。
.......上面的代碼不變..........
.box3{
width: 100px;
height: 100px;
background-color: black;
position:absolute;
right:0px;
bottom:0px;
}
.........省略代碼.......
<div class="box1">
<div class="box2">
<div class="box3"></div>
</div>
</div>二、絕對定位的注意點(diǎn)
(1)如果一個(gè)絕對定位的元素是以body作為參考點(diǎn),那么其實(shí)是以網(wǎng)頁首屏的寬度和高度作為參考點(diǎn)的,而不是以整個(gè)網(wǎng)頁的寬度和高度作為參考點(diǎn)的。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>D152_LimeLightOfAbsolutePosition</title>
<style>
.box1{
width: 100px;
height: 100px;
background-color: red;
position:absolute;
bottom:0px;
right:0px;
?
}
.box2{
width: 2000px;
height: 100px;
background-color: blue;
position:
}
.box3{
width: 200px;
height: 2000px;
background-color: black;
?
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
</body>
</html>(2)一個(gè)絕對定位的元素會(huì)忽略祖先元素的padding屬性。
.box4{
height: 300px;
width: 300px;
background-color: yellow;
padding:50px;
/*position:absolute;*/
/*boder:20px black ;*/
}
.box5{
height: 100px;
width: 100px;
background-color: red;
position:absolute;
left:0px;
top:0px;
}
</style>
</head>
<body>
<div class="box4">
<div class="box5"></div>
</div>“HTML絕對定位的參考點(diǎn)及注意事項(xiàng)有哪些”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
網(wǎng)站標(biāo)題:HTML絕對定位的參考點(diǎn)及注意事項(xiàng)有哪些
網(wǎng)站路徑:http://chinadenli.net/article44/ihjghe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、外貿(mào)建站、商城網(wǎng)站、、營銷型網(wǎng)站建設(shè)、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)