views:

2467

answers:

3

How can I scale a div to 100% height and width inside of another element? In my case a sourrounding td. Since I'm a plugin I can not control the other HTML on the page. Here is my HTML:

<body style="height:100%;">
  <table width="600px" height="400px" border="1">
    <tr>
      <td style="background-color:silver;">Cell 1</td>

      <td style="background-color:silver;">
    <div style="height:100%; background-color:yellow;">
      <div style="min-height:100%; height:100%; background-color:red;">
        Cell 2
      </div>
    </div>
      </td>
    </tr>
  </table>
</body>

So, the Cell 2 div should be maximized. Is there a cross browser way to do this? Why is this so complicated?

+1  A: 

Why bothing having a div within a div if its going to be 100% of the height and the width? Is there no other way of just using the containing div for your purpose?

It probably isnt working because height fails unless the containg element has some definite height applied to it.

Sam152
I need the div for adding a google map to it.
mzehrer
Cant you just put in the google map and let it fill the original div?
Sam152
+3  A: 

Look at this SO question as well ... after reviewing the top rated answer in that question, it looks like you have to set the height of the container to 100% and "min-height, height" of a child element to 100%.

Go to this website for more info - the HTML below is stripped-down version of the website

<div style="height=100%">
  <div style="min-height:100%;height:100%;background-color:red;">  
    put your content here 
  </div> 
</div>
roman m
This doesn't work for me, see my edited example in the question.
mzehrer
?? your table is 400px high, the div won't go past that
roman m
+2  A: 

Using javascript / jquery you can easily get the height of the parent element and resize your div accordingly.

However, as the div is located in a table cell, the width is not fixed as the cell would expand and contract according to the contents of the other cells in the table. So there really is no correct width, the cell will adapt itself according to the contents of all cells.

By the way, your height problem would be easily solved setting it to 400px, but I guess the shown table structure is just an example (1 row, 400px height...).

jeroen
I thought that this can be solved using HTML/CSS alone. And yes, the 400px are just for example.
mzehrer
Like I said, there is no correct answer because the height and width of table cells change automatically, so I don´t think that a html/css solution exists.
jeroen