javascript - 如何在父 div 中使用 y-overflow-scroll 调整 div?

标签 javascript jquery html css

我在 <td> 中遇到以下问题细胞: parent <div class="editor-window">包含 <label>和一个 child <div> . child <div>附加了另一个 <div>页面加载时。

JSFiddle .

var propertyGrid = $("<div class='property-table' />");
var editorWindow = $("#property-editor");

editorWindow.append(propertyGrid);
.content {
    //    hard-coded values for fiddle
    width: 225px;
    height: 200px;
}
.editor-panel {
    height: 100%;
    width: auto;
}
.editor-window {
    border: 1px solid rgba(61, 61, 61, 0.75);
}
.v-scroll-window {
    overflow-y: scroll;
}
.editor-header {
    text-align: center;
    display: block;
    height: auto;
    width: 100%;
    background-color: #b4b4b4;
    color: #00004f;
    font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 12px;
    font-weight: 600;
}
.max-window {
    width: 100%;
    height: 100%;
}
.property-table {
    display: table;
    width: 206px;
    height: 100%;
    border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="content">
    <tr>
        <td class="editor-panel">
            <div class="editor-window max-window">
                <label class="editor-header">Property Editor</label>
                <div class="v-scroll-window max-window">
                    <div class="max-window" id="property-editor" /></div>
            </div>
        </td>
    </tr>
</table>

问题是父级<div>#property-editor正在溢出其父级:
div overflow on y-axis

header <label>必须保持固定,而较低的 <div>有垂直滚动。关于如何修复溢出的任何想法?

最佳答案

最简单的解决方案——使用calc()对于 height (如果您有固定的 header 大小并且不需要 support IE9- ):

.v-scroll-window {
    overflow-y: scroll;
    height: calc(100% - 14px);
}

固定片段 ( JSFiddle ):

var propertyGrid = $("<div class='property-table'/>");
var editorWindow = $("#property-editor");

editorWindow.append(propertyGrid);
.content {
    width: 225px;
    height: 200px;
}

.editor-panel {
    height: 100%;
    width: auto;
}

.editor-window {
    border: 1px solid rgba(61, 61, 61, 0.75);
}

.editor-header {
    text-align: center;
    display: block;
    width: 100%;
    background-color: #b4b4b4;
    color: #00004f;
    font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    font-size: 12px;
    font-weight: 600;
    margin: 0;
}

.max-window {
    width: 100%;
    height: 100%;
}

.v-scroll-window {
    overflow-y: scroll;
    height: calc(100% - 14px);
}

.property-table {
    display: table;
    width: 217px;
    height: 100%;
    border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<table class="content">
    <tr>
        <td class="editor-panel">
            <div class="editor-window max-window">
                <h5 class="editor-header">Property Editor</h5>
                <div class="v-scroll-window max-window">
                    <div class="max-window" id="property-editor"></div>
                </div>
            </div>
        </td>
    </tr>
</table>

顺便说一句:

The HTML Label Element (<label>) represents a caption for an item in a user interface. It can be associated with a control either by placing the control element inside the <label> element, or by using the for attribute. Such a control is called the labeled control of the label element. With one input can be assosiated few labels.

你不应该使用 label tag在这种情况下——你没有 <form>或控制元件。我认为可以使用 Heading elements 中的内容,例如 <h5> .

关于javascript - 如何在父 div 中使用 y-overflow-scroll 调整 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33741352/

相关文章:

javascript - Angular:将 SQL 数据加载到文本框中

javascript - 如何通过在javascript中搜索多个属性值来逐个筛选?

javascript - 使用 Jquery 选择一个 td 元素

javascript - 使用 jQuery 从下拉列表中选择后清除其余的 DIV

html - ASP.NET MVC - Razor - 使用操作、 Controller 和 html 属性重载按钮

javascript - 数组中的逻辑或

javascript - 在运行时以编程方式引用 JavaScript 文件

jquery - 如何对 2 个表使用 LIKE 查询?

javascript - 如何保存已填写的表单的一部分并使用标题中的步骤号在 JQM 中导航

html - 为什么我的标题没有固定在列中。