Solved

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

Posted on 2009-04-01
5
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

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

Author Comment

by:josephdaviskcrm
ID: 24040731
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
ID: 24040787
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
ID: 24040863
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
ID: 24040899
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
disable data migrations in visual studio 2017 4 50
html form layout 4 36
ASP.net Moving Visual Studio 2015 project to 2017 2 41
output in HTML in Powershell 5 28
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…
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

726 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