Fix First Column of a Bootstrap Table

一笑奈何 提交于 2019-11-27 12:50:50
Guruprasad Rao

Ok.. Remove all your js code and you can do this with some CSS tricks as below:

DEMO

CSS

.table > thead:first-child > tr:first-child > th:first-child {
    position: absolute;
    display: inline-block;
    background-color: red;
    height: 100%;
}

.table > tbody > tr > td:first-child {
    position: absolute;
    display: inline-block;
    background-color: red;
    height: 100%;
}

.table > thead:first-child > tr:first-child > th:nth-child(2) {
    padding-left: 40px;
}

.table > tbody > tr > td:nth-child(2) {
    padding-left: 50px !important;
}

$('#table') means your finding element by id table.

$('.table') means your finding elements by class table.

These are the CSS selectors you used in css.

In your case, your table had id table so you can select that table using $('#table').

And you don't have any html elements using class table, so you'll get nothing when you select using $('.table').

As I tested @Guruprasad Rao 's answer , it has a bug if you display th, td are : "inline-block" instead of default display :"table-cell" width of column 1 in header and width of column 1 in tbody are not same width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!