Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align 2 images, one to right other to left inside div

Tags:

html

css

I have a in my webpage which carries 2 images. I want one image to be aligned left and other to the right end of the division.

The JsFiddle

Here's my HTML:

<div class="header">
<img id ="ttl" src="Home_files/images/ttl.png">
<img id ="se" src="Home_files/images/se.png">
</div>

and CSS:

.header {
position: relative;
top: 0%;
height: 20%;
}
/*Header CSS*/
img#ttl {
position: relative;
top:50%;
height: 50%;
left: 0px;
}
img#se {
position: relative;
top:60%;
height:30%;
vertical-align:right;
margin-right: 2%;
}

PS: I tried float:right;. Its works in in Chrome and FF but not in IE. And ofcourse this div has a parent div. But I don't think that will be a problem.

like image 787
tumchaaditya Avatar asked May 17 '13 07:05

tumchaaditya


2 Answers

You can wrap the images inside a position relative container and use position: absolute; to position them to bottom left and bottom right

Demo

<div class="wrap">
    <img src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
    <img src="http://images.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" />
</div>

div.wrap {
    width: 600px;
    border: 1px solid #f00;
    height: 300px;
    position: relative;
}

.wrap img {
    border: 1px solid blue;
     position: absolute;
    bottom: 0;
}

.wrap img:nth-of-type(1) {
    left: 0;
}

.wrap img:nth-of-type(2) {
    right: 0;
}

Note: Am using nth-of-type to select images so that I don't have to declare classes for each image, if you want to support older browsers, you need to add class for each image and replace :nth-of-type with those classes

like image 84
Mr. Alien Avatar answered Oct 19 '22 23:10

Mr. Alien


try this

<div class="header">
    <div class="left"><img id ="ttl" src="Home_files/images/ttl.png"></div>
    <div class="right"><img id ="se" src="Home_files/images/se.png"><div>
</div>

CSS

.left{
  float:left;
}
.right{
    float:right;
}

Demo

like image 29
Pawan Lakhara Avatar answered Oct 19 '22 22:10

Pawan Lakhara