PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 2, 2022

[FIXED] How to make div height to 100% of parent td

 August 02, 2022     css, html, html-table     No comments   

Issue

This is my current code:

table{
    table-layout: fixed;
}
table tr td{
    height: 100%;
}
table tr td div{
    height: 100%;
    background: red;
}
<table width="200" border="1">
  <tbody>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div>Test</div></td>
      <td>Lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>

As you can see the red div doesn't take the 100% of the parent td. I can't set fix dimensions to the parents, as they should adjust automatically to the content.

How can I set the div height to be 100% like the parent td height?


Solution

This should work for you:

table{
    table-layout: fixed;
    height:100%;
}

table tr td div{
    height: 100%;
    background: red;
    top:0;
}
<table width="200" border="1">
  <tbody>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td><div>Test</div></td>
      <td>Lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>



Answered By - RacoonOnMoon
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing