Solved

align div to bottom of parent div

Posted on 2007-03-26
8
934 Views
Last Modified: 2013-11-19
Hi
Im may be missing something really simple but can someone tell me whether you can make a div stick to the bottom of its parent div.

In the below example im building a rounded box with a min-height of 300px, the outer div has the min height applied to it and i need the div for the top section at the top(which is fine) and the div for the bottom section to stick to the bottom of the box.

I usually leave the height out of the css so the box just streches depending on content, but i need to apply a min-height

Any ideas???

/////////// HTML

<div id="factsheet">
<div id="factsheet_top"></div>

<div id="factsheet_bot"></div>
</div>


/////CSS

div#factsheet {
      margin:0;
      width:360px;
      float:left;
      background:url(../images/business/orange/box_middle.gif) repeat-y;
      height:300px;

}

div#factsheet_top{
      background:url(../images/business/orange/box_top.gif) no-repeat;
      width:360px;
      height:6px;
}

div#factsheet_bot{
      background:url(../images/business/orange/box_bottom.gif) no-repeat;
      width:360px;
      height:6px;
      clear:both;
}
0
Comment
Question by:socross
  • 4
  • 4
8 Comments
 
LVL 30

Accepted Solution

by:
Steggs earned 500 total points
ID: 18794275
Hello,

To make an element always be at the bottom of the parent, you need to use positioning. The parent has to have position:relative;, otherwise the child will position itself relative to closest parent with a position or the browser window.

<div style="position:relative;height:200px;background-color:#369;">
I am the parent

<div style="position:absolute;bottom:0;height:50px;background-color:#f00;">
This div will always be at the bottom of its parent.
</div>


</div>

Regards
Steggs
0
 
LVL 1

Author Comment

by:socross
ID: 18795194
works great

although when i place an image (which is the same width as the parent div), it pushes the bottom div out of alignment,

<div id="bus_serv">
<div id="bus_serv_top"></div>
<img src="images/business/orange/services_title.gif" />
<div id="bus_serv_bot"></div>
</div>

ANy ideas why??

-s-
0
 
LVL 30

Expert Comment

by:Steggs
ID: 18795235
Try adding enough padding-bottom for the absolutely positioned div to the parent:

<div style="position:relative;height:200px;background-color:#369;padding-bottom:50px;">
I am the parent

<div style="position:absolute;bottom:0;height:50px;background-color:#f00;">
This div will always be at the bottom of its parent.
</div>


</div>
0
 
LVL 1

Author Comment

by:socross
ID: 18795289
still no good??

-s-
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:Steggs
ID: 18795302
Is this stuff on the web? can you put it on the web?

Or post all the code here, including the css

Cheers
0
 
LVL 1

Author Comment

by:socross
ID: 18795371
i dont have a copy online yet, here is the css/html, if thats no good i will post a copy online.

-s-

///////////////////CSS

div#bus_serv  {
      margin:0;
      position:relative;
      background:url(../images/business/orange/box_middle.gif) repeat-y;
      width:360px;
      height:150px;
      float:left;
      padding-bottom:6px;
}
div#bus_serv_top{
      background:url(../images/business/orange/box_top.gif) no-repeat;
      width:360px;
      height:6px;
}

div#bus_serv_bot{
      background:url(../images/business/orange/box_bottom.gif) no-repeat;
      width:360px;
      height:6px;
      position:absolute;
      bottom:0;
}

/////////////////HTML

<div id="bus_serv">
<div id="bus_serv_top"></div>
<img src="images/business/orange/services_title.gif" />
<div id="bus_serv_bot"></div>
</div>
0
 
LVL 30

Expert Comment

by:Steggs
ID: 18795676
y0 dude,

If you could get it online that would be better.

Cheers
0
 
LVL 1

Author Comment

by:socross
ID: 18795965
hi ive got to call it a day now, i will be able to post a copy in the morning and work on it tommorrow.

Thanks for your help so far.

Sam
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

910 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

22 Experts available now in Live!

Get 1:1 Help Now