-1

I have one table data. there thead is fixed. I have added scroll only for tbody

tbody{
display: block;
    height: 102px;
    overflow-y: auto;
}

SO here, thead and tbody is mismatching in alignment because of scrollbar. Scrollbar takes some widtin tbody

https://jsfiddle.net/MohaideenIsmail/6hm2oaLe/

It is giving like this. how to avoid this?

enter image description here

Mohaideen
  • 209
  • 1
  • 2
  • 13

2 Answers2

0

Hi just replace the style

CSS

table {
    /* width: 100%; */ /* Optional */
    /* border-collapse: collapse; */
    border-spacing: 0;
    border: 2px solid black;
}[![enter image description here][1]][1]

table tbody,
table thead { display: block; }

thead tr th { 
    height: 30px;
    line-height: 30px;
    /* text-align: left; */
}
table > thead > tr > th:not(first-child){
                min-width:145px;
            }
            table > tbody > tr > td:not(first-child) {
                min-width:145px;
            }

table tbody {
    height: 60px;
    overflow-y: auto;
    overflow-x: hidden;
}

tbody { border-top: 2px solid black; }

tbody td, thead th {   
    border-right: 1px solid black;
}

tbody td:last-child, thead th:last-child {
    border-right: none;
}

Check on JsFiddle

Rohit Goyani
  • 1,246
  • 11
  • 26
Gayathri Mohan
  • 2,924
  • 4
  • 19
  • 25
0

Well try this below code, I have added width to your th and td which align them perfectly, but on mobile device you have to use media queries and reduce the width of th, as below.

table > thead > tr > th{
  width:9.15%;
  text-align:left;
}   
tbody > tr > td{
  width:5%;
    text-align:left;
}

Align your text according as you want them to be.

frnt
  • 8,455
  • 2
  • 22
  • 25