Solved

align div to bottom of parent div

Posted on 2007-03-26
8
926 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

760 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

21 Experts available now in Live!

Get 1:1 Help Now