Solved

CSS - set table height to 100% in order to fill it's containing element

Posted on 2009-04-01
5
409 Views
Last Modified: 2012-05-06
I have a table that sits inside of a div tag of variable height.  I need the table to expand vertically to fit the div at whatever size it is.  I of course tried to give it a css style of height:100%, which works perfectly on a table element in IE7, but it doesn't seem to work in any of the other browsers.  Anybody have any tricks up their sleeves?
0
Comment
Question by:josephdaviskcrm
5 Comments
 
LVL 23

Expert Comment

by:apresto
Comment Utility
can you post the code (simplified if poss) of the div and table so we can play with it?
0
 

Author Comment

by:josephdaviskcrm
Comment Utility
just create a div and add a style to it with css of a set height, like 200px or something.  Give it a background-color so you can see the space it covers.  Then stick a table inside of it with one row and one cell.  Give it also a background color so you can see the space it covers.  Now try and make the table expand vertically to fill the whole container div.  Horizontal coverage is not important.
0
 
LVL 11

Expert Comment

by:level9wizard
Comment Utility
If you haven't declared a doctype:
http://www.w3.org/QA/2002/04/valid-dtd-list.html

or validated your code:
http://validator.w3.org/

... then our more than likely going to see different results in various browsers. After you do these two things, you should be able to simply do this:

<!-- in html -->
<div id="myDiv"> content here... </div>

/* and in css */
#myDiv
{
   display: block;
}
0
 

Author Comment

by:josephdaviskcrm
Comment Utility
I don't think that's really what I'm going for...

I'm using a table because it has a valign property and I need the content of this area on my homepage to be centered vertically.

So I stuck this table into the div, gave the table a css style of 100% and stuck my content inside the table (which has 1 row and 1 cell).  Once again, this works perfectly in IE7, but no in any other browser.
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 500 total points
Comment Utility
Try this.  The 10px pixel padding was added just to show that the table is inside the div.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 

<title>Please Help!</title> 

<style type="text/css">

html, body {

    padding: 0px;

    maring: 0px;

    height: 100%;

    border: 0px;

}

#div {

    height: 300px;

    background-color: blue;

    padding: 10px;

}

#table {

    background-color: green;

    width: 100%;

    height: 100%;

}

</style>

</head> 

<body>

<div id="div">

<table id="table"><tr><td>Test</td></tr></table>

</div>

</body> 

</html>

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
CSS is a visual language used to classify objects and define rules about how they should be displayed. CSS skills aren’t restricted to developers anymore, there is a big benefit to having a basic understanding of the language, regardless of your occ…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now