0

I looked for another question but couldn't find it

https://jsfiddle.net/0u15em89/

table>tbody {
  display: block;
  max-height: 50px;
  overflow: auto;
}

table {
  width: 100%;
}
<table>
  <tbody>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
  </tbody>
</table>

add scroll to tbody,

I want to make the width 100% by removing the space between td and scroll.

Is it possible to do without fixing the width of td?

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
  • 1
    Please check this link, https://stackoverflow.com/questions/1457563/equal-sized-table-cells-to-fill-the-entire-width-of-the-containing-table . you can use table-layout: fixed; and equal width to cells. – Pratiksha Kale Mar 16 '20 at 08:42
  • Thank you, but I can't fix the width of th or tr. – user13031767 Mar 16 '20 at 08:51

3 Answers3

0

If I got your question correctly , you may be able to get a full width by the style below :

table { 
width: 100%; 
border-spacing: 0; 
}

table tbody, table thead { 
 display: block; 
}  

thead tr th { 
height: 40px;  
line-height: 40px; 
} 

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

tbody td, thead th { 
width : 200px; 
} 
td { 
text-align:center; 
} 
0

Try this one, First, Remove this whole part

 table>tbody {
      display: block;
      max-height: 50px;
      overflow: auto;
    }

second, surround a table tag with a div tag Ex : <div><table>......</table></div>. make that div tag scroll like this,

div {
  max-height: 50px;
  overflow: auto;
}
Hiran
  • 7
  • 2
0

Apply below css to tr will help you to fix the width issue without providing specific width to td.

table>tbody {
  display: block;
  max-height: 50px;
  overflow: auto;
}

table {
  width: auto;
  display: inherit;
}

tr {
  display: inline-table;
  width: 100%;
}
<table>
  <tbody>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
    <tr>
      <td>content1</td>
      <td>content2</td>
      <td>content3</td>
      <td>content4</td>
    </tr>
  </tbody>
</table>
Sumit Patel
  • 4,530
  • 1
  • 10
  • 28