具有固定/左列和可滚动主体的 HTML 表格?

标签 html angularjs css

我正在尝试创建一个占据屏幕宽度 70% 的简单表格。但是,如果表格中的内容溢出了表格的 70%,那么表格应该可以水平滚动。

HTML:

<div ng-app="">
<div ng-controller="EventController">
    <div class="outter">
        <table class="countries">
            <tbody>
                <tr>
                    <th>Country name</th>
                    <td ng-repeat="countryNames in Countries">{{countryNames.countryName}}</td>
                </tr>
                <tr>
                    <th>Population</th>
                    <td ng-repeat="population in Countries">{{ population.countryName }}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
</div>

CSS:

.outter {
width: 70%;
}

.countries {
tr {
    td {            
        height: 50px;
        font-size: 11px;
        text-align: center;
        vertical-align: middle;
        font-weight: normal;
    }
}
}

这是我的 fiddle :http://jsfiddle.net/oampz/QW97X/2/

最佳答案

.countries 表指定 width100% 并将 overflow: auto 添加到 .outter div.

.outter {
    width: 70%;
    overflow: auto;
}
.countries {
    width: 100%;
}

fiddle :http://jsfiddle.net/QW97X/4/

关于具有固定/左列和可滚动主体的 HTML 表格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23738287/

相关文章:

html - 闯入:避免-第一个元素(IE,Edge,Firefox)忽略CSS

javascript - 动态地将事件类应用到导航栏

javascript - 当 if 条件多次满足时从数组返回多个值

jquery - div随着jquery height auto消失

javascript - StickyNav - 调试

HTML5 CSS3 模态窗口,点击外部关闭

html - 自定义元素的 CSS 属性不会继承给子元素

angularjs - Angular Material ng-messages在解决后不会消失

javascript - jQuery动态获取标签的内容

javascript - 添加类后无法从元素中删除该类