-2

I have little problem in my web page. I use bootstrap 4 and in table box I set inside other table as in the picture below. How to make the height of table inside the same as the hieght of the box (td)?

enter image description here

html:

<table class="table table-bordered">
   <tbody>
      <tr>
         <td>REVERT</td>
         <td>
            <table class="table" style="height: 100%">
               <tbody>
                  <tr>
                     <td>Name</td>
                     <td>LONG TEXT</td>
                  </tr>
               </tbody>
            </table>
         </td>
      </tr>
   </tbody>
</table>

Browser: enter image description here enter image description here

creimers
  • 4,975
  • 4
  • 33
  • 55
Nurzhan Nogerbek
  • 4,806
  • 16
  • 87
  • 193

3 Answers3

1

Because the table have CSS attribute margin-bottom: 20px, you need to add an override CSS to remove this attribute:

<table class="table table-bordered">
   <tbody>
      <tr>
         <td>REVERT</td>
         <td>
            <table class="table table-no-margin" style="height: 100%">
               <tbody>
                  <tr>
                     <td>Name</td>
                     <td>LONG TEXT</td>
                  </tr>
               </tbody>
            </table>
         </td>
      </tr>
   </tbody>
</table>
<style>
    .table-no-margin { margin: 0 }
</style>
Sang Lu
  • 308
  • 3
  • 10
1

This is happening because your nested table has a margin-bottom of 1rem(default bootstrap css). override it that's it.

Working example

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<table class="table table-bordered">
   <tbody>
      <tr>
         <td>REVERT</td>
         <td>
            <table class="table" style="height: 100%; margin-bottom:0px;">
               <tbody>
                  <tr>
                     <td>Name</td>
                     <td>LONG TEXT</td>
                  </tr>
               </tbody>
            </table>
         </td>
      </tr>
   </tbody>
</table>
neophyte
  • 6,540
  • 2
  • 28
  • 43
  • I tried this before but it didnt work for me. For thats why I asked this question in stackoverflow. – Nurzhan Nogerbek Apr 01 '17 at 11:18
  • There can be no other reason for this to happen..I think your custom css is not overriding the bootstrap css. Try adding an id to the table then style it. add your custom css after the bootstrap css. if none of them works try adding !important, although that is not recommended. – neophyte Apr 01 '17 at 11:29
  • In the end of my post you can see the screens from browser and they shows that margin style of table is not overriding. Here parent is td element and child is table. So I need to give the same height to child element as in parent. – Nurzhan Nogerbek Apr 01 '17 at 11:37
  • Post your full html – neophyte Apr 01 '17 at 12:13
0

This question has been asked many times before, but I'll answer it specifically for your scenario. It's not an issue of removing padding/margins.

In order to get a 100% height table, it's container must also be 100% height. So in this case set the containing td to height: 100%...

Demo on Codeply

       <td>REVERT</td>
       <td style="padding:0;height: 100%;">
           <table class="table" style="height: 100%">
                <tbody>
                     <tr>
                        <td>Name</td>
                        <td>LONG TEXT</td>
                     </tr>
                </tbody>
           </table>
       </td>
Community
  • 1
  • 1
Carol Skelly
  • 351,302
  • 90
  • 710
  • 624