Javascript 如果父绝对div更改高度,请调整相对div的大小?

Javascript 如果父绝对div更改高度,请调整相对div的大小?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,绝对div的新高度为800。如何自动调整相对容器的大小 .亲戚{ 位置:相对位置; 宽度:600px; 高度:400px; 背景:111人; } .绝对的{ 位置:绝对位置; 顶部:20px; 左:20px; 宽度:300px; 高度:200px; 背景:fff; } 定位元素将从文档的正常流中删除,因此更改其大小不会改变其父元素的高度 然而,即使它们比它们的祖先大,由于溢出,您仍然可以看到它们 在您的情况下,删除 圣集装箱{ 溢出:隐藏; } .st内容{ 溢出y:隐藏; } 然后,它仍将成

绝对div的新高度为800。如何自动调整相对容器的大小

.亲戚{ 位置:相对位置; 宽度:600px; 高度:400px; 背景:111人; } .绝对的{ 位置:绝对位置; 顶部:20px; 左:20px; 宽度:300px; 高度:200px; 背景:fff; }
定位元素将从文档的正常流中删除,因此更改其大小不会改变其父元素的高度

然而,即使它们比它们的祖先大,由于溢出,您仍然可以看到它们

在您的情况下,删除

圣集装箱{ 溢出:隐藏; } .st内容{ 溢出y:隐藏; } 然后,它仍将成为默认溢出:可见,所以您的绝对元素仍将可见溢出,所以您将能够使用页面的滚动条完全查看它

document.getElementById'btn'.onclick=function{ document.getElementById'absolute'.style.height =document.getElementById'relative'.clientHeight*2+'px' }; html,正文{ 保证金:0; 身高:100%; } 相对的{ 位置:相对位置; 宽度:100%; 身高:100%; 背景:111人; } 绝对的{ 位置:绝对位置; 顶部:20px; 左:20px; 宽度:300px; 高度:150像素; 背景:aaf; }
正如Oriol所说,您不应该使用position:absolute,因为它将元素从文档流中移除,因此不会注册高度。如果您正在查找一个示例,例如您发布的行,则可以将容器设置为“显示:无”,如果希望容器显示和隐藏,请使用jquery的slideDown或slideToggle:

HTML

JS

绝对div如何改变高度?例如:点击Jetzt Angebot anforden
<button>Click Me</button>

<div class="info">
   <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

   <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
.info{
  display: none;
  background: black;
  color: #FFF;
}
$("button").click(function(){
  $(".info").slideDown();
  $(this).hide(); //the example you used hid the button after clicking
});