1

What would be the best and most correct way of hiding part of an image source in an img tag

Say I have the following:

<img alt="" src="myimage.jpg" class="photo" />

My target is to have the image enclosed in a rounded corner container, which will obviously cover the corners of image at the top.

Should I just go and put an absolute positioned element on top of the image as if you're putting a cut-out paper on top of a photo or is there some kind of alternative?

2 Answers 2

3

If your intention is that the image gets rounded corners, you could just use border-radius on it. If you need the container to have the rounded corners and that the image gets clipped, use overflow: hidden for it.

You can find a demonstration for it in this fiddle: http://jsfiddle.net/frozenkoi/hwDYV/

What you want is something similar to this

<div class="contact">
    <img src=http://jsfiddle.net/img/top-bg.png /><a href="#">Username</a>
</div>

With this CSS:

DIV.contact {background: silver; border-radius: 8px; margin: 10px auto 0 5px; width: 200px; text-align: center; overflow: hidden}
DIV.contact IMG {display: block; width: 100%; }

Note that the image is just a blue rectangle.

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

Comments

1

Several options:

  • Process the images server side to apply the transformation.
  • Overlay an absolutely positioned mask image on top of the images.
  • Use some clever CSS with rounded corners and absolutely positioned transparent elements to achieve the same effect as the mask image.

1 Comment

I was thinking about setting a background-image to the img but then released that it would go behind the image defined in the source :/ I'm trying to eliminate image processing. The target of this site is to be a forum like setup where people upload their images to their profile.

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.