[英]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.