2016-03-06 28 views
-1
<div id="content" style="background-color: red; height: 100%;"> 
<div id="object1" style="width: 100%; background-color: green; height: 100px; position:fixed;"> 
</div> 
<div id="object2" style="width: 100%; background-color: blue;height: 100px;" > 
</div></div> 

我想修復div object1的位置固定,object2應該與其分開。沒有固定的位置,一切工作正常。如何在不使用css的margin和padding屬性的情況下實現這一點。如何在父div中分隔子div,當其中一個div被修復時。

回答

0

如何做到這一點,而無需使用 CSS的marginpadding屬性。

使用position財產,height:100%width:100%bodyhtml

html, 
 
body { 
 
    height: 100%; 
 
    width: 100%; 
 
    margin: 0 
 
} 
 
#content { 
 
    background-color: red; 
 
    height: 100%; 
 
    position: relative 
 
} 
 
#object1 { 
 
    width: 100%; 
 
    background-color: green; 
 
    height: 100px; 
 
    position: fixed; 
 
} 
 
#object2 { 
 
    width: 100%; 
 
    background-color: blue; 
 
    height: 100px; 
 
    position: absolute; 
 
    top: 120px; 
 
}
<div id="content"> 
 
    <div id="object1"> 
 
    </div> 
 
    <div id="object2"> 
 
    </div> 
 
</div>

相關問題