Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep div at the bottom of another div - css

Tags:

css

© 1965 - 2010

I want the #copyright to be at the bottom of #outer

Here is the css for #copyright

#copyright{
    position:relative; margin-bottom:0px; width:672px; height:20px; color:#FFF;
}
#yr{
    margin:auto;
}

#f{ position:absolute; right:0px; text-align:center;
}

Thanks Jean

like image 234
X10nD Avatar asked Jul 08 '10 07:07

X10nD


People also ask

How do you get an element to stick to the bottom of a div?

Just set element child to position: relative and than move it top: 100% (that's the 100% height of the parent) and stick to bottom of parent by transform: translateY(-100%) (that's -100% of the height of the child).

How do I make a div stick to another div?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do I position something at the bottom of a page in CSS?

If position: absolute; or position: fixed; - the bottom property sets the bottom edge of an element to a unit above/below the bottom edge of its nearest positioned ancestor. If position: relative; - the bottom property makes the element's bottom edge to move above/below its normal position.


2 Answers

#copyright {
    position: absolute;
    bottom: 0;
}
#outer {
    position: relative;
}

This will have the unfortunate side effect though that #copyright does not count towards the height of #outer anymore, in your example #outer would be 0px high. You can add a bottom-padding to #outer if you're working with fixed heights.

#copyright {
    position: absolute;
    bottom: 0;
    height: 200px;
}
#outer {
    position: relative;
    padding-bottom: 200px;
}
like image 173
deceze Avatar answered Oct 12 '22 22:10

deceze


  1. define height of #outer
  2. set #outer to position:relative;
  3. set #copyright to position:absolute; bottom: 0; left: 0;
    #outer {
      height: 100px;
      border: 1px solid red;
      position: relative;
    }

    #copyright {
      position:absolute; 
      height: 30px; 
      bottom: 0; 
      left: 0;
      border: 1px solid black;
      width: 300px;
    }   
    <div id="outer">
       <div id="copyright">
           <span id="yr">© 1965 - 2010</span>
           <span id="f"></span>
           <span id="d"><span>
       </div>
    </div>

Also, never use "0px". There is no such thing as zero pixels, only zero. Correct way is "right: 0;"

like image 9
Māris Kiseļovs Avatar answered Oct 12 '22 21:10

Māris Kiseļovs