Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix an image position relative to another image with different screen sizes

I'm writing a website/iPad app (using PhoneGap), where I have 1024x768 images on a slide show. I'd like to position another image, e.g. the home icon, on top of the 1024x768 images, at exactly the same position, no matter the screen size (e.g. high/low resolution PC screen, or 1024x768 tablet display). I tried absolute, but the position changes in different displays, and it's not the same position as I originally set up in CS 5.

like image 781
David Zhao Avatar asked Sep 19 '11 17:09

David Zhao


People also ask

How do I fix the position of a picture?

To position an image relative to a page, select the image and from the menu bar below it, select “Fix position on page”. To open the “Image options” sidebar, select the overflow menu (three dot), followed by “All image options”. To learn more about formatting images in Google Docs, see this article in our Help Center.

How to make image responsive height?

To make an image responsive, you need to give a new value to its width property. Then the height of the image will adjust itself automatically. The important thing to know is that you should always use relative units for the width property like percentage, rather than absolute ones like pixels.

How to position an image in a div CSS?

Step 1: Wrap the image in a div element. Step 2: Set the display property to "flex," which tells the browser that the div is the parent container and the image is a flex item. Step 3: Set the justify-content property to "center." Step 4: Set the width of the image to a fixed length value.

How to give image position in HTML?

HTML | <img> align Attribute. The <img> align attribute is used to set the alignment of an image. It is an inline element. It is used to specify the alignment of the image according to surrounding elements.


2 Answers

Similar to the other answers, but if you prefer not to define the width and height, you can use float:

http://jsfiddle.net/RprTY/

<div>
    <img src="http://placekitten.com/300/300">    
    <img src="http://placekitten.com/30/30" id="smallone">
</div>

CSS:

div{
    float: left;
    position: relative;
}

img{
     vertical-align: bottom;   
}

#smallone{
    top: 0;
    left:0;
    position:absolute;   
}

As long as the parent container is set to either position: relative or position: absolute, then the absolutely positioned image should be positioned relative to the top left corner of the parent. This should be completely independent of screen resolution.

like image 65
James Montagne Avatar answered Nov 15 '22 06:11

James Montagne


Put your 1024x768 image in a div of the same size. Include your home icon in that div as well. Give the div position relative, and the home icon position absolute and it will be absolutely positioned inside it's parent div.

like image 45
katy lavallee Avatar answered Nov 15 '22 06:11

katy lavallee