html - 最大宽度 : 100% not working

标签 html css web

我正在尝试做一个类似聊天的东西,它有以下结构:

<div class="chat">
    <div id="messagesWrap" class="chat-messages">
        <table id="chat">
            <tr>
                <td>
                    A certain long text, whos length overflows the "chat" container div.
                </td>
            </tr>
            //some more <tr><td> pairs go here with JS.
        </table>
    </div>
</div>

此外,我还有以下 CSS:

.chat
{
    position: absolute;

    min-width: 400px;
    width: 20%;
    height: 100%;
    left: 0;
    right: auto;
    top: 0;
    bottom: 0;
}

.chat-messages
{
    width: 100%;
    max-width: 100%;
    height: calc(100% - 40px);
    overflow-x: hidden;
    overflow-y: scroll;
}

#chat
{
    height: 100%;
    max-width: 100%;
}

#chat>tbody
{
    max-width: 100%;
}

这一切的问题在于,max-width 属性对表和 tbody 都不起作用。 td 的内容使整个结构到 table 的宽度超出了 maxwidth,这应该是最顶层 div 宽度的 100%。无论我做什么,或者我尝试在谷歌中搜索什么,我都找不到解决方案。也许有比 max-width 更高优先级的东西?

此外,我正在使用 chrome。

最佳答案

max-width 属性防止元素超过其父元素的宽度,因此您可以为表容器 class chat-messages 设置一定的宽度并使用max-width: 100%; 在你的表格中。在两者中使用 max-width: 100%; 意味着它们都可以填满整个屏幕。

关于html - 最大宽度 : 100% not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23323487/

相关文章:

php - mysql_fetch_assoc 不返回任何内容(不是 null、不是 0、不是 "")

javascript - 没有插件和框架的幻灯片图像

移动图像后,HTML + CSS 图像链接将不起作用

html - flex-basis 和 box-sizing

javascript - 如何同时对多个输入乘以值求和

javascript - 打印 iframe 不包含 CSS

javascript - JQuery Accordion 中可调整大小的 Google 可视化

html - 为什么这些链接不会改变我的 div 的高度?

c++ - 在我的网站上运行python,C,C++应用程序

PHP 警告 : include(/var/www/html/. ...../lib/Cake/Error/ErrorHandler.php): 无法打开流错误