我的页面上有四个 div。 outer_div
left-container
其他三个: header
right-container
我不关心 header
和 left-container
。实际上我的 right-container
div 包含一个动态表。
问题 是当表的大小增长时, right-container
div 不会自动增长。我的意思是它的大小保持不变。
代码:
<html>
<body>
<div id="outer_div" style="background-color:Gainsboro; position:relative; top:50px; left:50px;height:550px;border-radius:8px; border:groove; width:1240px">
<div id="header" style="background-color:Khaki ; position:relative; top:5px; left:5px;height:50px;border-radius:8px; border:groove; width:1225px">
<h1 style="left:550px; position:relative; top:-7px">Admin Panel</h1>
</div> <!-- header ends-->
<div id="lef-container" style="background-color:LightSteelBlue ; position:absolute; top:65px; left:4px;height:475px;border-radius:8px; border:groove; width:280px">
</div> <!--left-container ends -->
<div id="right-container" style="background-color:LightSteelBlue ; position:absolute; top:65px; left:294px;height:475px;border-radius:8px; border:groove; width:936px">
<!-- this div contains dynamica table -->
</div> <!--right-container ends -->
</div> <!--outer div ends -->
</body>
</html>
如何解决?这是 CSS :
border:1px solid #000000;
border-collapse:collapse;
width:200px;
}
.mytable td{
background:#cccccc;
border:1px solid #000000;
}
表的CSS :
var tab=document.createElement('table');
tab.style.width='800';
原文由 user3119163 发布,翻译遵循 CC BY-SA 4.0 许可协议
您需要有一个动态的
width
和height
属性,例如fit-content
。问题是您使用的是固定宽度936px
以及固定高度475px
所以 div 永远不会拉伸到比这更大。你可以这样做:然后在 CSS 中:
当
right-container
中的元素增长时,right-container
将拉伸以适应它们。