Solved

align div to bottom of parent div

Posted on 2007-03-26
8
938 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:socross
ID: 18795289
still no good??

-s-
0
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
The viewer will learn how to count occurrences of each item in an array.

786 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