当div中的一个div被修复时,如何在父div中分隔子div。

时间:2016-03-06 22:46:55

标签: html css

<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属性的情况下实现。

1 个答案:

答案 0 :(得分:0)

  

如何在不使用marginpadding属性的情况下实现这一目标   的CSS。

positionheight:100%

中使用width:100%属性和bodyhtml

&#13;
&#13;
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;
}
&#13;
<div id="content">
  <div id="object1">
  </div>
  <div id="object2">
  </div>
</div>
&#13;
&#13;
&#13;