Solved

align div to bottom of parent div

Posted on 2007-03-26
8
954 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 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