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
Solved

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

Posted on 2009-04-01
5
418 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET MVC - Views 3 21
send email part1 9 28
Bootstrap list items overlap 3 11
IF statment In Powershell 12 17
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

837 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