This is a discussion on "Child div expand to fit parent?" within the Web Page Design section. This forum, and the thread "Child div expand to fit parent? are both part of the Design Your Website category.
|
|
|
|
|
![]() |
||
Child div expand to fit parent?
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
So i have done many a search in various forums and on google and i came up short so i figure i'll post my delima here.
Ive been using tables for some time now but knowing it will be better for me in the long run, im trying to do away with them and use div's and css. I have a parent div (we'll call it main) with three children div's (we'll call them top, middle and bottom) inside. The main div's height is set to 100% (thats 100% of the body) while the top and bottom div's heights are both set to 100px. To keep the site looking the way i want it to, i would like the middle div to expand to fit the remaining space in the parent div. If i set the middle div's height to 100% it displays at the same size of the parent div (i know this is because of the way div's work and the box model and so on...). But i need it to display at 100% of the remaining space inside the main div. I know this is pretty easy using tables but how can it be done using div's and css? Any ideas? Many thanks in advance!! |
|
|
|
|||
|
Re: Child div expand to fit parent?
Could you post your code so far?
Setting the height to 100% restricts the vertical flow, For the footer try using position: absolute; I quickly wrote this css which should work...
And this structure for the divs
So nesting them creates a page of 100% and then subtracts the 100px needed for the footer. Is this any help to you? P.S neither have been checked for validation, I generally leave this until after i have a working model. Last edited by Bocaj; Apr 20th, 2008 at 01:39. |
|
|||
|
Re: Child div expand to fit parent?
wow, thats real clever the way you nested the div's like that. and it works great too!!
my code was just like:
on a short side note: ive noticed that when defining css attributes many people (you included, Bocaj) will say something like:
|
|
|||
|
Re: Child div expand to fit parent?
The difference between <div id and <div class is
id can be used only once on a page and class can be used as many times as required. Hope that helps. Pat |
|
||||
|
Re: Child div expand to fit parent?
Here's a quick read on ID's vs classes.
Generally, most developers will use ID's for things like footers, wrappers and navigation. It just separates them from the mix of classes, and since there's only one per page, it makes sense to use ID's in these conditions.
Last Blog Entry: The Google Misconception (Feb 3rd, 2008)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Javascript Parent and Child menu in Safari?? | TR123 | JavaScript Forum | 3 | Mar 8th, 2007 14:15 |
| Submitting a parent form from a child window in IE 7 | livehed | JavaScript Forum | 0 | Feb 15th, 2007 16:23 |
| parent child forms | mrproggie | ASP.NET Forum | 1 | Aug 12th, 2006 17:49 |
| Parent Child accesssing | greenkhan | ASP.NET Forum | 1 | Jun 20th, 2005 09:21 |
| Filling a textbox on a parent web user control from a child | neilault | ASP.NET Forum | 8 | Oct 27th, 2004 08:06 |