html - html 表格宽度在 Firefox 和 IE 中失控

标签 html css internet-explorer firefox css-tables

<分区>

我应该用 div 构建它,但我必须为我的客户(虚拟用户)使用表。 因此,我使用在 Chrome 中完美运行的 CSS 构建了这个 html 表格。

我已经阅读了一些相关主题,但就是没有掌握关键技巧!希望有人告诉我错误。

这是我的 CSS,我有 jsfiddle demo here (仅适用于 Chrome) 请先在 Chrome 中查看 jsfiddle 演示,然后尝试 Firefox,你就会明白我的意思了。

#content_container {
    width:960px;
}
#content_container .fullcontainer > table {
    border-bottom: 4px solid #222;
}
#content_container .fullcontainer {
width:inherit !important;
margin: 0 auto !important;
padding: inherit !important;
}
#content_container table.eurostyle {
    margin: 25px auto !important;
    border-collapse: collapse !important;
    font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif !important;
    text-shadow: 1px 1px 1px #eee;
}
table td img.alignleft {
margin: 0;
}
body h2 {
font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif !important;
font-weight: bold;
}
.eachtop {
    border-top: 4px solid #222;
    border-color: #000;
}
.eachaside {
    border-top: 1px solid #222;
    border-top: 1px solid #ccc;
    font-size: 12px;
}
table td {

}
table h2 {
    margin: 2px 0;
    line-height: 1.1em;
    font-size: 22px;
}
.eachtop > td:first-child {
/*height: 40px;*/
padding: 3px 0;
}
.tdfit {
    padding: 0 0 0 1px;
    line-height: 0;
}
.ctable {
    margin: 0 0 0 0px;
}
.ctable td img, .tdfit img {
    max-width: 100%;
    height: auto;
}
.ctable td {
    padding: 1px;
    border: 1px solid #000000;
    border-top: none;
    border-bottom: none;
    line-height: 0.9;
}
.ctable td img {

        }

最佳答案

table-layout: fixed 添加到您的表格中,您的问题将得到解决。

来自 CSS 技巧:

Things get a lot sturdier and more predictable with property/value in place. The layout is fixed based on the first row. Set the width of those, and the rest of the table follows.

这意味着表格的内容决定宽度,表格第一行的样式现在将决定下面其余行的宽度,这使得布局更多,您猜对了,已修复!

工作示例(经过测试的 Firefox):

http://jsfiddle.net/gt5t01ov/2/

关于html - html 表格宽度在 Firefox 和 IE 中失控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26491745/

相关文章:

javascript - 如何在 <video> 元素上触发 MediaError?

javascript - 在某些浏览器中,转义的 html 字符未被 jquery .html() 转义

html - 检测 Bootstrap 导航栏是否折叠或不成 Angular

html - 如何仅在设备上显示响应式网站 View

html - 字体在 IE7 和 8 中看起来更大 - 但只有一个网站的一页

javascript - 将 IE 11 用户代理字符串设置为 IE 9

html - 怪癖模式合法吗?

c# - 当使用 Microsoft.Office.Interop.Word 将 html 转换为 Word 时,字体大小不一样

php - 无法使用 DB_NAME : Access denied for user

javascript - 如何创建用于相机控制的操纵杆