javascript - 以 Angular 向表格添加滚动条

标签 javascript html css angularjs

我有以下 Angular 表代码。我只想为表体(不包括表头的表行)设置垂直滚动条,我该怎么做?

因为所有行都是由 ng-repeat 生成的。我不知道如何添加溢出样式。

html:

            <div class="nu-table">
                <div class="nu-table-row nu-header">
                    <div class="nu-table-cell">A</div>
                    <div class="nu-table-cell" style="width: 33%">B</div>
                    <div class="nu-table-cell" style="width: 34%">C</div>
                </div>
                <div class="nu-table-row nu-striped pointer-cursor" ng-repeat=" map in mapList">
                    <div class="nu-table-cell"  ng-bind="map.A"></div>
                    <div class="nu-table-cell">{{map.B}}</div>
                    <div class="nu-table-cell" ng-bind="map.C"></div>
                </div>
            </div>

CSS 内容如下:

.nu-border-table{
    border: solid 1px #ccc; 
}

.nu-border{
    border: solid 1px #ccc;
}


.nu-table{
    background-color: #fff;
    padding: 5px;
    overflow: scroll;
    display: table;
    table-layout: fixed;
    width: 100%;
}

.nu-table-row{
    display: table-row;
    position: relative;
    width: 100%;
}

.nu-table-row:hover{
    background-color: #cee6fa;
}


.nu-table-row.nu-striped.selected{
    background-color: #cee6fa;
}

.nu-table-row:last-child{
    border-bottom: none;
}

.nu-margin{
    margin:5px;
}

.nu-table-cell{
    display: table-cell;
    border-right: solid 1px #ccc;
    border-top: solid 1px #ccc;
    min-height: 2em;
    padding-top: .3em;
    position: relative;
    word-wrap: break-word;
    padding-left: 2px;
}

.nu-table-cell:last-child{
    border-right: none;
}

.nu-striped:nth-child(even) {
    background-color: #f9f9f9;
}

.nu-striped:nth-child(even):hover{
    background-color: #cee6fa;
}

.nu-header {
    background-color: #dedede;
    border-bottom: solid 2px #bebebe;
    font-weight: bold;
}

最佳答案

尝试在行周围添加一个 div(未测试):

    <div class="nu-table">
        <div class="nu-table-row nu-header">
            <div class="nu-table-cell">A</div>
            <div class="nu-table-cell" style="width: 33%">B</div>
            <div class="nu-table-cell" style="width: 34%">C</div>
        </div>
        <div class="nu-table-body">
           <div class="nu-table-row nu-striped pointer-cursor" ng-repeat=" map in mapList">
              <div class="nu-table-cell"  ng-bind="map.A"></div>
              <div class="nu-table-cell">{{map.B}}</div>
              <div class="nu-table-cell" ng-bind="map.C"></div>
          </div>
        </div>
    </div>

和css(设置你想要的高度)

.nu-table-body {
    overflow-y:auto;
    max-height:500px;
}

关于javascript - 以 Angular 向表格添加滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28350930/

相关文章:

css - 使用 jCarousel 将一整组嵌套的 div 变成一个可点击的对象

html - 一个固定大小的 div,文本保留在其中

javascript - 反斜杠前后字符串 ("/") 字符

javascript - 为什么 JS 解构赋值对数字起作用

javascript - Eloquent Javascript 练习 : Deep Comparison

Javascript - 选择名称更改问题

html - 如何使用CSS添加居中背景

javascript - 单选按钮未正确验证

javascript - Bootstrap 3 Glyphicon 未在下拉菜单中对齐

html - 将导航栏中的 IMG 元素居中