CSS如果Absolute Child DIV落在边界外,请调整父DIV大小 [英] CSS Adjust Parent DIV size if Absolute Child DIV falls outside boundaries

查看:354
本文介绍了CSS如果Absolute Child DIV落在边界外,请调整父DIV大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个父div,它是指定的宽度和高度。如果我有一个孩子div在里面,那是在边界之外,是否有一种方法使父div调整大小适合孩子div?



EX: / p>

 < div style =width:500px; height:500px; position:relative;> 
< div style =width:300px; height:300px; position:absolute; top:250px;>
一些内容
< / div>
< / div>

正如你可以看到,在这个例子中,子div会将底部的父div溢出50px。我不想使用overflow:auto,因为只是创建滚动条。我真的想让父div调整和添加50px的高度,以弥补子div。

解决方案

/ p>

http://jsfiddle.net/jURc9/8/



您希望将子项从父项顶部向下移动250像素,因此不要使用 top:250px 。使用 margin-top:250px; position:relative;


I have a parent div that is a specified width and height. If I have a child div inside that, that is outside the boundaries, is there a way to make the parent div adjust size to fit the child div?

EX:

<div style="width:500px; height:500px; position:relative;">
  <div style="width:300px; height:300px; position:absolute; top:250px;">
    Some Content
  </div>
</div>

As you can see in this example the child div would overflow the parent div on the bottom by 50px. I do not want to use overflow:auto because that just creates scrollbars. I really want the parent div to adjust and add 50px in height to compensate for the child div.

解决方案

Check this out.

http://jsfiddle.net/jURc9/8/

You want to push the child down 250px from the top of the parent so do no use top:250px. Use margin-top:250px; and position:relative;

这篇关于CSS如果Absolute Child DIV落在边界外,请调整父DIV大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆