Chrome 中的 CSS 表格和最大宽度不起作用

标签 css google-chrome firefox css-tables

这是我的 CSS 代码;

#wrap {
    width:50em;
    max-width: 94%;
    margin: 0 auto;
    background-color:#fff;  
}

#head {
    width:50em;
    height:10em;
    max-width: 100%;
    margin: 0 auto;
    text-align:center;
    position: relative;
}

#css-table { 
    display: table; 
    margin: 1em auto;
    position: relative;
    width:50em;
    max-width: 100%;            
}

#css-table .col { 
    display: table-cell; 
    width: 20em;
    padding: 0px;
    margin: 0 auto;
}

#css-table .col:nth-child(even) { 
    background: #fff;
}

#css-table .col:nth-child(odd) { 
    background: #fff;
    border-right: 4px double #b5b5b5;
}

还有我的 HTML 代码;

<div id="cont">
    <div id="css-table">
        <div class="col">123</div>
        <div class="col">123</div>
    </div>
</div>

当我缩放 Firefox 窗口时,表格可以很好地缩放到 300 像素宽度的视口(viewport)......就像我想要的那样。但在 Chrome 中,只有当视口(viewport)宽度大于 50em 时,表格才会看起来正常。如果我缩小 Chrome 窗口,表格的右侧会溢出。

Chrome 这样做有什么原因吗?

最佳答案

从技术上讲,Chrome 遵循规则,因为 ma​​x-width 应该只应用于 block 元素

来自 MSDN 文档:

The min-width/max-width attributes apply to floating and absolutely positioned block and inline-block elements, as well as some intrinsic controls. They do not apply to non-replaced inline elements, such as table rows and row/column groups. (A "replaced" element has intrinsic dimensions, such as an img or textArea.)

该表(或在您的情况下为 display:table)在技术上应该不起作用或不受支持。 FF 显然很好地遵守了它,但您可能需要想出另一种解决方案,删除 display:tablemax-width

max-width property

MSDN Doc

关于Chrome 中的 CSS 表格和最大宽度不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12232858/

相关文章:

google-chrome - 加载大文件时,nginx 上的 ERR_CONTENT_LENGTH_MISMATCH 和 Chrome 上的代理

windows - 如何在 Chrome 中启用 ActiveX?

python - Selenium、Python、Marionette 证书警告

javascript - Firefox 19 从 JavaScript 打印 PDF

javascript - FireFox 按钮子 span 和 li 不可点击或悬停

所有浏览器中的 CSS 问题

javascript - 隐藏滚动条并使用 CSS 向左向右滑动

html - 相同的字体文件、相同的 PC、相同的操作系统、相同的浏览器、相同的代码——两个不同站点上的两种不同渲染结果。是什么赋予了?

HTML 中的 PHP 和 SQL 表

javascript - 重置 GIF 动画并显示 :none on Chrome 的正确方法