Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

align div to bottom of parent div

Posted on 2007-03-26
8
Medium Priority
?
995 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:
Mark Steggles earned 2000 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:Mark Steggles
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:socross
ID: 18795289
still no good??

-s-
0
 
LVL 30

Expert Comment

by:Mark Steggles
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:Mark Steggles
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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 the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

810 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