[英]My html div is making grow their parent container beyond its limit
I have a problem: My div (red one) that is inside a table-td (that I cannot change), is making the parent container grow and show a scroll not matter which percentage I use for my div width. 我有一个问题:位于table-td(我无法更改)中的div (红色)使父容器增长并显示滚动,无论我为div宽度使用哪个百分比。
The following image shows the actual problem: 下图显示了实际的问题:
I also have an example in fiddle 我也有一个小提琴的例子
<div class="principal">
<table width="100%" class="sometable"><tbody><tr><td>
<!-- my code starts here -->
<div id="div_translation_container">
<div class="taxonomy_section_body">
<div class="taxonomy_section_row">
<div class="taxonomy_section_cell">6000 ABD</div>
<div class="taxonomy_section_cell">
i
</div>
<div class="taxonomy_section_cell">
i
</div>
<div class="taxonomy_section_cell">
i
</div>
<div class="taxonomy_section_cell">
i
</div>
<div style="clear: both;"></div>
</div>
</div>
</div>
<!-- my code ends here -->
</td>
</tr>
</tbody>
</table>
</div>
CSS CSS
.principal{
width:900px;
background-color:black;
overflow:auto;
}
#div_translation_container{
background-color:red;
border-top: 2px solid #141414;
padding-top: 10px;
width: 50%;
}
.taxonomy_section_body {
display: inline-block;
margin: auto;
min-height: 10px;
overflow-x: auto;
width: 100%;
margin-bottom: 10px;
}
.taxonomy_section_row {
background-color: yellow;
white-space: nowrap;
}
.taxonomy_section_cell {
background-color: blue;
display: inline-block;
width: 250px;
overflow: hidden;
height: 30px;
white-space: nowrap;
padding: 5px;
text-align: center;
}
The table width is 100% The columns is 80% and my div is 50% 表格宽度为100%列为80%,而我的div为50%
but somehow these percentages are not considered.. 但不考虑这些百分比。
NOTE* I cannot change the table or the principal div because my html code is encrusted dynamically, and it shouldn't affect anything outside its boundaries 注意*我不能更改表或主体div,因为我的html代码是动态嵌入的,并且不应影响其边界之外的任何内容
Like this? 像这样?
#div_translation_container{
.....
position:absolute;
}
Fiddle : https://jsfiddle.net/hoj2Lwdv/1/ 小提琴: https : //jsfiddle.net/hoj2Lwdv/1/
If I understand your problem correctly, just remove overflow or make overflow:hidden to .principal: 如果我正确理解了您的问题,请删除溢出或使溢出:隐藏为.principal:
.principal{
width:900px;
background-color:black;
overflow:hidden;
}
I'm not sure if this is what you're looking for. 我不确定这是否是您要找的东西。 Initially, you had your section body display property set to inline-block.
最初,您将截面主体显示属性设置为inline-block。 I only removed it, since all your divs are wrapped inside the table (display:table if you were to style it in CSS) to avoid display issues.
我只删除了它,因为所有div都包裹在表中(如果要在CSS中设置样式,则为display:table),以避免显示问题。
.principal{
width:600px;
height: 300px;
background-color:black;
overflow:auto;
} }
#div_translation_container{
background-color:red;
border-top: 2px solid #141414;
padding-top: 10px;
width: 60%;
position:absolute;
} }
.taxonomy_section_body {
margin: auto;
min-height: 10px;
overflow-x: auto;
width: 100%;
margin-bottom: 10px;
} }
.taxonomy_section_row {
background-color: yellow;
white-space: nowrap;
} }
.taxonomy_section_cell {
background-color: blue;
display:inline-block;
width: 250px;
overflow: hidden;
height: 30px;
white-space: nowrap;
padding: 5px;
text-align: center;
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.