父div在绝对位置隐藏的溢出

时间:2016-08-29 06:28:11

标签: html css css3

我有一个非常具体的要求,即父divabsolute:position和孩子divabsolute position和父div我有overflow:hidden因此,width的额外div隐藏了,但这不起作用,我知道父div必须与position:relative匹配,但是根据我的代码的当前结构,我无法将父div positionabsolute更改为relative,只是想知道是否有办法处理此问题? / p>

以下是JSfiddle示例,我希望浅红色框隐藏在父div下,以便子div位于父级内。

这是我的代码



.wrapper {
  position: absolute;
  left: 100px;
  top: 100px;
  width: 400px;
  height: 350px;
  background: #666666;
  padding: 10px;
}
.wrapper-inner {
  position: absolute;
  width: 450px;
  height: 380px;
  background: #fecccc;
}

<div class="wrapper">
  <div class="wrapper-inner">
    Content goes here
  </div>
</div>
&#13;
&#13;
&#13;

6 个答案:

答案 0 :(得分:1)

您似乎错过了在overflow:hidden课程中添加wrapper

&#13;
&#13;
.wrapper{position:absolute; left:100px; top:100px; width:400px; height:350px; background:#666666; padding:10px; overflow:hidden;}
.wrapper-inner{position:absolute; width:450px; height:380px; background:#fecccc;}
&#13;
<div class="wrapper">
	<div class="wrapper-inner">
    	Content goes here
    </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

根据您的要求检查此代码:

.wrapper {
  position: absolute;
  left: 100px;
  top: 100px;
  width: 400px;
  height: 350px;
  background: #666666;
  padding: 10px;
  overflow: hidden;
}

答案 2 :(得分:0)

请查看我的fiddle

.wrapper{position:absolute; left:100px; top:100px; width:400px; height:350px; overflow:hidden; background:#666666; padding:10px;}
.wrapper-inner{position:relative; width:100%; height:100%; background:#fecccc; overflow-y:scroll;}
<div class="wrapper">
	<div class="wrapper-inner">
    	Content goes here Content goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes hereContent goes here
    </div>
</div>

答案 3 :(得分:0)

除非我误解了您的要求,否则您不希望看到子div延伸到父div之外。你提到过overflow:hidden,但实际上并不存在于你的小提琴中。将它添加到.wrapper类似乎完成了我认为您的要求。

答案 4 :(得分:0)

DEMO

CSS

.wrapper-inner {
  position: absolute; /* positioned wrt it parent */
  top:10px; /* account for 10px padding in parent */
  bottom:10px;
  left:10px;
  right:10px;
  /* width: 450px;
  height: 380px; */
  background: #fecccc;
}

答案 5 :(得分:0)

您错过了父包装中的 overflow:hidden

.wrapper {
  position: absolute;
  left: 100px;
  top: 100px;
  width: 400px;
  height: 350px;
  background: #666666;
  padding: 10px;
  overflow: hidden
}

.wrapper-inner {
  position: absolute;
  width: 450px;
  height: 380px;
  background: #fecccc;
}

简而言之,您已回答了自己的问题! :)