简体   繁体   English

如何获得表格宽度以保留在其容器中?

[英]How do I get a table width to stay with in its container?

How do I get a table width to stay within its container? 如何获得表格宽度以保留在其容器中?

.outerSection:nth-child(4) .innerSection:nth-child(1) .sectionData:nth-child(1) table{ 
    margin:15px 15px 20px 15px;     
    width:100%;     
    max-width:100%; 
}  

This may have some compatibility issues with some older browsers ( http://caniuse.com/#feat=calc ), but you could try: 这可能与某些旧版浏览器( http://caniuse.com/#feat=calc )存在兼容性问题,但是您可以尝试:

width: calc(100% - 30px)  /*to subtract the 15px on each side*/

Alternatively, instead of having that margin you could add padding to its parent container (the .sectionData:nth-child(1) class, or wrap the table in it's own div with padding). 另外,您可以在其父容器(.sectionData:nth-​​child(1)类,或使用填充将表包装在其自己的div中)中添加填充,而不是保留该空白。 I believe there are a few ways to accomplish what you're looking for. 我相信有几种方法可以完成您想要的。

EDIT: Here is a fiddle with the 'calc' CSS: http://jsfiddle.net/7h8cgsjh/1/ 编辑:这是与'calc'CSS的小提琴: http : //jsfiddle.net/7h8cgsjh/1/

The table will not overflow the container UNLESS: 该表不会溢出容器,除非:

1. The table has position:absolute;
2. The table has a width greater then 100%
3. The table has a greater pixel width then the container does
4. The table uses margin-left or margin-right
5. The table has a padding, which then you could do width: auto

Those are the only simple ways a table could overflow a table. 这些是表溢出表的唯一简单方法。 If it is overflowing anyhow, and one of the above 3 conditions are not met, please post your container and table CSS. 如果仍然溢出,并且不满足以上三个条件之一,请发布您的容器和表CSS。

A possible to solution to fix yous would be setting the width to auto, or setting the width to 100% and making a 0px margin. 解决该问题的一种可能方法是将宽度设置为自动,或者将宽度设置为100%并设置0px的边距。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得Bootstrap容器与另一个div保持内联? - How do I get a Bootstrap container to stay inline with another div? 当表格比其容器宽时,我如何让TD不忽略其宽度? - How do I have a TD not ignore it width when the table is wider than its container? 为什么这个内部HTML表格的宽度取决于其内容? 如何设置容器的宽度? - Why this inner HTML table have the width determined by its content? How can I set to the width of its container? 如何在CLIP上对图像进行y中心,但如果它小于其容器,则让它保持顶部对齐? - How do I y-center an image ON CLIP but let it stay top aligned if it is smaller than its container? 当内容更宽时,如何使元素保持在浏览器的窗口宽度之内? - How can I get an element to stay within the browser's window width when its content is wider? 当HTML表格的宽度设置为100%时,如何获取HTML表格的边距? - How do I get Html Table to respect margins when its width is set to 100%? 无论其他容器发生变化,如何让我的 div 容器保持原位? - How do I get my div container to stay in place regardless of the changes happening in other containers? 如何获得拆分层的内容容器最大宽度以匹配全宽层的宽度? - How do I get the content container max-width of a split tier to match the width of a full width tier? 如何让 div 浮动到其容器的底部? - How do I get a div to float to the bottom of its container? 如何设置中心容器以保持响应速度? - How do I set a center container to stay responsive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM