3

I have this piece of HTML code:

<div>
  <div>
    <image src="image-inside-pic-png.png" alt="">
  </div>
  <image src="pic.png" alt="" />
</div>

The pic.png (300x300 px) is the main image. I would like to put the image-inside-pic-png.png (20x20 px) inside of it. When I apply position: absolute; on the small image, it works only momentarily. If I change the size of either, it no longer works.

So my question is, how can I move the small image always in the big image - and this small image will be always 15px from the top and 30px from the right margin of the big image?

Thank you for help

1
  • sounds like you're using a background image, which should be set via CSS. Is image-inside-pic-png.png part of the content, or is it simply used for style? Commented Feb 16, 2012 at 14:33

4 Answers 4

13

I think this should work:

HTML:

<div>
  <img src="image-inside-pic-png.png" alt="" class="inner-image"/>
  <img src="pic.png" alt="" />
</div>

CSS:

div {
  position: relative;
}

.inner-image {
  position: absolute;
  top: 15px;
  right: 30px;
}

Anyway, make sure you need to do this with HTML. Maybe it's better to simply edit the image with Photoshop or Gimp. Or maybe one image it's only for styling purpose, then you should use CSS.

Sign up to request clarification or add additional context in comments.

Comments

9

Without changing your markup this can be achieved e.g. using display:inline-block to the outermost div element (so it won't extend for 100% of the available width) and position relative + absolute for outermost div and thumbnail

see this fiddle: http://jsfiddle.net/cRqhT/3/
border and image size are defined for simplicity

Comments

0

put both images in one div which uses position:relatvie, then apply position:absolute to images, and adjust the value as you need.

Comments

0
 **html**

  <div class="images">
          <img src="./images/Rectangle.png" alt="bg"/>
          <img src="./images/lady.png" alt="lady" class="lady-image"/>
  </div>
   


**css**
      .images {
       position: relative;
       }

       .lady-image {
        position: absolute;
        top: 0;
        right: 0;
        }

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
When answering you should include a description of your code so that others can understand how it addresses the question as asked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.