Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align two images to bottom left & right corners of a <div>

Tags:

html

css

My page currently has something a bit like the following, in order to put two images on each side of my page header-bar.

    <div id="header" >
        <div style="float:left" >
            <img src="media/logo1.png"/>
        </div>
        <div style="float:right" >
            <img src="media/logo2.png"/>
        </div>
    </div>

While this works on the left-right alignment, I can't find a good tweak to get both images aligned to the bottom of the parent <div>. They seem to align to the top instead.

However I reckon this might be just the wrong approach to start with. Therefore all suggestions welcome on the best way to make it work - or better, how to arbitrarily force an image to a chosen corner of the parent <div>.

like image 774
Mr. Boy Avatar asked Jan 31 '10 16:01

Mr. Boy


1 Answers

If your header has a fixed height, just use absolute positioning:

<div id="header" >
    <img id="logo1" src="media/logo1.png"/>
    <img id="logo2" src="media/logo2.png"/>
</div>

Then in your CSS:

#header     { position: relative; height: 200px}
#header img { position: absolute; bottom: 0; left: 0}
#logo2      { left: auto; right: 0}

Or, If your header is only as tall as logo1.png then use this CSS instead:

#header     { position: relative;}
#logo2      { position: absolute; bottom: 0; right: 0}

This will cause logo1 to set the height of header and logo2 will just sit at the bottom of header and on the right.

like image 137
Doug Neiner Avatar answered Nov 15 '22 08:11

Doug Neiner