tags:

views:

102

answers:

4

i am taking an image from a source, say, facebook. now when i want to insert that image in a container with fixed width and height, the image stretches to fit that space. is there a way the image can display in its normal size and the rest of the area clipped out?

A: 

Show it as a background image

Ray
+4  A: 
<div style="width: 100px; height: 100px; background-image: url(your image); background-repeat: no-repeat;"></div>

Then in the above DIV you can play with CSS

  • width/height
  • background-position

to create different crop effects.

Marco Demajo
A: 

Use this : http://www.w3schools.com/css/pr_background-position.asp

background-position: 5px 5px;

and then set the height and width of the div

height: 55px;

width: 55px;

AjayP
+1  A: 

You can use the CSS clip property:

#image_element
{
position:absolute;
clip:rect(0px,60px,200px,0px);
}

The downside of using clip is that the element has to be absolutely positioned, and is only available with the 'rect' shape.

See:

David Thomas