Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stick a div to the bottom of another div?

Okay, so this is the parent div:

#left {
    width: 50%;
    height: 100%;
    background-color: #8FD1FE;
    float: left;
    opacity:0.75;
    filter:alpha(opacity=75);
    -webkit-transition: all .45s ease;  
    -moz-transition: all .45s ease; 
    transition: all .45s ease; }

And this is the div inside the div:

#reasons {
background-image:url('arrow1.png');
background-repeat: no-repeat;
height: 94px;
width: 400px;
margin: 0 auto 0 auto; }

I've tried a bunch of different methods, but I can't seem to keep the the second div centered and stuck to the bottom of the first div.

like image 276
Dee Avatar asked Oct 08 '11 03:10

Dee


People also ask

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

Just set the parent div with position:relative . Then, the inner item you want to stick to the bottom, just use position:absolute to stick it to the bottom of the item.

How do you stick two divs together?

The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.

How do I place a div at the bottom without absolute?

Without using position: absolute , you'd have to vertically align it. You can use vertical-align: bottom which, according to the docs: The vertical-align CSS property specifies the vertical alignment of an inline or table-cell box.

How do you position a div in the bottom right corner of another div?

To place a div in bottom right corner of browser or iframe, we can use position:fixed along with right and bottom property value assigned to 0.


1 Answers

First, make the outer div a layout parent:

#left {
     /* ... */
     position: relative; /* anything but static */
     /* ... */
}

Now let's fix the inner div to the bottom:

#reasons {
    /* ... */
    position: absolute;
    bottom: 0;
    /* ... */
}

Now it's fixed to the bottom, but we need to center it:

#reasons {
    /* ... */
    left: 50%;
    margin: 0 0 0 -200px; /* 200px is half of the width */
    /* ... */
}

See a demo on JSFiddle.

like image 112
icktoofay Avatar answered Oct 25 '22 13:10

icktoofay