views:

985

answers:

3

Hi all,

I've seen this question asked in a couple other contexts on SO, but I thought it would be worth asking again for my particular case. I'm trying to create some re-usable CSS classes for more consistency and less clutter on my site, and I'm stuck on trying to standardize one thing I use frequently.

I have a container div that I don't want to set the height for (because it will vary depending on where on the site it is), and inside it is a header div, and then an unordered list of items, all with CSS applied to them. It looks a lot like this:

Widget

I want the unordered list to take up the remaining room in the container div, knowing that the header div is 18px tall. I just don't know how to specify the list's height as "the result of 100% minus 18px". Does anyone have any advice in this situation?

Thanks very much.

A: 

I use Jquery for this

function setSizes() {
   var containerHeight = $("#listContainer").height();
   $("#myList").height(containerHeight - 18);
}

then I bind the window resize to recalc it whenever the browser window is resized (if container's size changed with window resize)

$(window).resize(function() { setSizes(); });
puffpio
@puffpio, Certainly JS is a way to accomplish this on a case by case basis. But as I said, I'm trying to make the CSS generic, to be applied across multiple pages (that inherit from a master page, incidentally). So I'd prefer not to use JS. But thanks for the answer.
Mega Matt
+1  A: 

Presuming 17px header height

List css:

height: 100%;
padding-top: 17px;

Header css:

height: 17px;
float: left;
width: 100%;
ghoppe
Yep, that's what I was getting at.
dclowd9901
That didn't work quite as well as I had hoped. My unordered list is being started beneath that header div. The header div is taking up space in the container, so putting padding-top of 17px on the list is just going to push it down 17px from where it already is in the picture above, not 17px from the top of the container div. Here's a pic of what I get with the CSS given in the answer above: http://i41.tinypic.com/mcuk1x.jpg. I appreciate the effort, though, and if there's something you think I'm missing, please let me know. Btw, I have overflow: auto on the unordered list as well.
Mega Matt
It would be a lot easier troubleshooting this if you posted actual css so we can see exactly what interactions are going on. Another thing you might try is negative top margin on your ul. `ul { margin-top: -17px; }`
ghoppe
A: 

I'm not sure if this work in your particular situation, but I've found that padding on the inside div will push content around inside of a div if the containing div is a fixed size. You would have to either float or absolutely position your header element, but otherwise, I haven't tried this for variable size divs.

dclowd9901