2017-04-22 54 views
0

我有div塊,應該顯示在整個頁面的寬度和高度。如何擠壓父塊底部的塊?

這裏面塊我還有一個div與位置固定:

<div class="parent"> 
    <div class="child"></div> 
</div> 

CSS:

.parent { 
    position:absolute; 
    left:0; 
    right:0; 
    bottom:0; 
    top:0; 
    background:green 
} 

.child { 
    position:fixed; 
    botttom:0px; 
    height:80px; 
    width:100% 
    background:yellow; 
} 

問題是,parent塊不顯示完整的頁面上,實習生塊.child不位於parent區塊的底部。

+0

'位置:fixed'元素涉及到的視口,而不是任何元素的父 – LGSon

+0

這是什麼意思? – Daniel

+0

這意味着無論您將其放置在標記中的哪個位置,它都會始終將其自身定位在相對於視口的位置,因此,如果您將它放在左/頂部0,它將始終保留在左上角 – LGSon

回答

1

試試這個代碼

<style> 
 
.parent { 
 
    position:absolute; 
 
    left:0; 
 
    right:0; 
 
    bottom:0; 
 
    top:0; 
 
    background:green; 
 
    width:100%; 
 
} 
 

 
.child { 
 
    position: fixed; 
 
    bottom: 0px; 
 
    height:80px; 
 
    width: 100%; 
 
    background:yellow; 
 
} 
 
</style> 
 

 
<div class="parent"> 
 
    <div class="child"></div> 
 
</div>

+2

OP的代碼工作雖然有拼寫錯誤,但我們不會發布錯誤的答案,我們評論和/或標記他們...甚至更糟糕的是,這隻會幫助_Try這個code_ ...下一次,添加一個體面的解釋 – LGSon

+1

與我的代碼有什麼不同? – Daniel