【问题标题】:HTML: Set scroll on div table-rowHTML:在 div 表行上设置滚动
【发布时间】:2017-06-06 14:45:39
【问题描述】:

您好,我尝试在 .chat .body 中设置滚动(溢出-y:滚动),我尝试了所有代码但不起作用。

提前致谢! ////////////////////////////////////////////p>

代码:

<div class="chat">
    <div class="head"></div>
    <div class="body">
        <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tbody>
                <tr>
                    <td align="left" width="40">
                        <img src="http://www.exclutips.com/wp-content/uploads/2015/08/wordpress-custom-user-avatar.png" style="
                            width: 32px;
                            height: 32px;
                            display: block;
                            border: 1px solid rgba(0, 0, 0, .1);
                            cursor: pointer;
                            ">
                    </td>

                    <td align="left" width="136">
                        <div class="user-name">User Name</div>
                    </td>

                    <td align="right">
                        <span class="online-icon"></span>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
    <div class="footer">
        <input type="text" placeholder="Search">
    </div>
</div>


<style type="text/css">

    * { font-family: "Segoe UI"; }

    html {
        font-size: 100%;
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        height: 100%;
    }

    body {
        margin: 0;
        padding: 0;
        background: #F2F2F2;
        height: 100%;
    }

    input, select {
        display: block;
        width: 100%;
        padding: 5px;
        outline: none;
        border-width: 1px;
        border-style: solid;
        border-radius: 0;
        background: #fff;
        font-size: 12px;
        color: #6B6B6B;
        appearance:normal;
        -moz-appearance:none;
        -webkit-appearance:none;
        border-color: #BDBDBD;
    }

    div, textarea, input, select, button, a { box-sizing: border-box; -moz-box-sizing: border-box; }

    .chat {
        display: table;
        border-left: 1px solid #ccc;
        position: fixed;
        height: 100%;
        top: 0;
        right: 0;
        bottom: 0;
        width: 200px;
        margin: 0;
        padding: 0;
        background: #E1E1E1;
    }
    .chat .head {
        display: table-row !important;
        height: 52px;
    }
    .chat .body {
        overflow-y: scroll;
        display: table-row;
        height: 100% !important;
    }
    .chat .body table {
        cursor: pointer;
        padding: 5px;
    }
    .chat .footer {
        display: table-row !important;
    }
</style>

在这里查看演示:http://chatiiii.hol.es/default.php

【问题讨论】:

标签: html css


【解决方案1】:

您可以使用jQuery 设置.body 高度:

* {  
    box-sizing:border-box;
    ...
}

.chat {
    display: block;
    ...
}

.chat .head {
    height: 52px;
    ...
}

.chat .body {
    overflow-y: auto;
    ...
}

和 jQuery

$(document).ready(function () {
    setSize();
    $(window).on('resize',setSize);
});

function setSize(){
    var CH = $('.chat').height(),
        HH = $('.chat .head').height(),
        FH = $('.chat .footer').height();
    $('.chat .body').height(CH-HH-FH);
}

查看完整示例here。

【讨论】:

    【解决方案2】:

    从.chat .body 中删除display: table-row;。

    【讨论】:

    【解决方案3】:

    在 .chat .body 类中使​​用这种样式,但是你应该在 html 中复制用户表,直到它超过页面的高度,然后你可以看到滚动。

    .chat .body {
        overflow-y: scroll;
        height: 80%;
    }
    

    您应该删除 display: table-row ,并且还给出一个小于 100% 的高度。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-21
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2014-04-20
    • 1970-01-01
    相关资源
    最近更新 更多