Getting a table to fill 100% height in a td

前端 未结 5 1125
灰色年华
灰色年华 2021-01-13 05:42

I\'m trying to rewrite a site in proper HTML. The site I\'m trying to replace was a complete mess. I\'ve run into a problem where I can\'t get a

t
相关标签:
5条回答
  • 2021-01-13 05:49

    ///how must set main table height

    <table bordercolor="#f6f6f6" style="height:100px;">
        <tr>
            <td style="padding:0px;">
                <table style="height:100%; width:100%;">
                    <tr>
                        <td style="border-right:1px solid #f6f6f6; width:50px;">Test1</td>
                        <td>Test2</td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    
    0 讨论(0)
  • 2021-01-13 05:55

    i got a one solution if you need your desired results you can adjust the padding of your (td.navigation a class link) through this you will get your results.

    apply this css:-

    td.navigation a {
        color: #837768;
        display: block;
        font-size: 1.2em;
        padding: 14px 5px;
        text-align: center;
        text-decoration: none;
    }
    
    0 讨论(0)
  • 2021-01-13 05:56

    100% height in a table cell is always a pain. Technically speaking a TD has no height (because that depends on its contents). What you are asking the browser to do is make the child 100% of its parent, which is 100% of its child, which is 100% of its parent ... You can see how that might be a problem.

    You could try adding an explicit height to the TD and using table-layout:fixed on the table. At least that way the browser knows the height of the parent without needing the height of the child but that still may not work.

    You might need to rethink how you go about this.

    0 讨论(0)
  • 2021-01-13 06:13

    So it's done here with divs, absolute positioning in %, and here's the part you won't like, with a specific height set in pixels. The trouble is, if you use table cells (td) the td's don't have height, and so any element inside will calculate 0 for 100% height.

    When we use div's the problem is different. We can make sure they retain their height property, but there's no way to tell the div on the left, "be the same height as the div in the center." At least no way I know of. That being said, it seems like your flash object is the tallest thing, and you could easily set the height of all three div's at a pretty pixel perfect amount. Then stretch the ul navigation list to the height to 100% of the div it's nested within.

    There's one other way to do this, that might meet your needs better, I'll detail it at the very bottom.

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>TheDavidFactor's Layout</title>
    
    <style type="text/css">
      body, html {
        background: black;
        width:100%;
        height:100%;
        padding:0;
        margin:0;
      }
      #left {
        position:absolute;
        top:10%;
        left:0;
        background: #eeeeee;
        width: 20%;
        padding: 2%;
        margin:0;
      }
      #right {
        position:absolute;
        top:10%;
        left:76%;
        background: #eeeeee;
        width: 20%;
        padding: 2%;
        margin:0;
      }
      #center {
        position:absolute;
        top:10%;
        left:24%;
        background: #ffffdffffd;
        width: 48%;
        padding: 2%;
        margin:0;
      }
      #flash {
        background:red;
        width: 500px;
        height: 500px;
        padding:0;
        margin:0;
      }
      ul {
        height: 500px;
        padding:0;
        margin:0;
        padding-left:25px;
        background: #4359ac;
        color: #ffffff;
      }
      li {
        height: 10%;
        padding:0;
        margin:0;
      }
    </style>
    
    </head>
    <body>
    
    <div id="left">
      <ul>
        <li>Spa</li>
        <li>Hotel</li>
        <li>Activities</li>
        <li>Hobbies</li>
        <li>Night Life</li>
        <li>Food</li>
        <li>Feedback</li>
        <li>Contact</li>
        <li>About Us</li>
        <li>Copyright</li>
      </ul>
    </div>
    <div id="center">
      <div id="flash">Here's your flash Object</div>
    </div>
    <div id="right">
      here's the right div
      <br>
      <p>Let's throw some random text in here to take up space for now.</p>
    </div>
    
    </body>
    </html>
    

    The other option you have is to wrap the three columns in a container div, and define a height for that div, then stretch each of the columns to 100% height within that container div.

    0 讨论(0)
  • 2021-01-13 06:14

    The best solution for this is to have the parent element of the button have a height of 100% as well, assuming you want your button to have a height of 100%.

    e.g

    <tr>
      <td><button class="btn" id="1">1</button></td>
      <td><button class="btn" id="2">2</button></td>
      <td><button class="btn" id="3">3</button></td>
      <td><button class="btn" id="plus">+</button></td>
      <td rowspan="2"><button class="btn btn-block" id="equals">=</button></td>
    </tr>
    

    CSS:

    td{
        height: 100%;
    }
    .btn {
        width: 100%;
        height: 100%;
    }
    

    That should work fine

    0 讨论(0)
提交回复
热议问题