Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning and overlaying image on another image

Tags:

html

css

image

See how the tiny Facebook icon is positioned in the lower right-hand corner over another image?

enter image description here

How can I do that using a combo of HTML/CSS/Rails/Prototype!? An example would be great. Perhaps in jsfiddle.net.

like image 570
keruilin Avatar asked Feb 26 '11 23:02

keruilin


People also ask

How do I position one image on top of another?

As the simplest solution. That is: Create a relative div that is placed in the flow of the page; place the base image first as relative so that the div knows how big it should be; place the overlays as absolutes relative to the upper left of the first image. The trick is to get the relatives and absolutes correct.

How do I overlay an image on another image in CSS?

Basically, you put both of your images in the same container. Give the container a position that isn't static (in my example, relative). Then give the overlay image position: absolute and position it however you want using bottom and right . Show activity on this post.

How do I put an image on another image in HTML?

To insert an image in HTML, use the image tag and include a source and alt attribute. Like any other HTML element, you'll add images to the body section of your HTML file. The HTML image element is an “empty element,” meaning it does not have a closing tag.


2 Answers

You can use css to solve the problem.

div {    position: relative;    display: inline;  }  .imtip {    position: absolute;    bottom: 0;    right: 0;  }
<div>    <img src="http://i.stack.imgur.com/Blaly.png" />    <img src="http://www.w3schools.com/favicon.ico" class="imtip" />  </div>

Basically, I've done more or less what ZDYN said, just that you need to include a display: inline in the container otherwise the container div spans the whole width.

like image 139
Sameer Goyal Avatar answered Sep 18 '22 19:09

Sameer Goyal


Here's a simple example using divs instead of images: http://jsfiddle.net/sqJtr/

Basically, you put both of your images in the same container. Give the container a position that isn't static (in my example, relative). Then give the overlay image position: absolute and position it however you want using bottom and right.

like image 33
zdyn Avatar answered Sep 20 '22 19:09

zdyn