Have an account? Sign in
Login  Register  Facebook
How to make a photo show only the center part, hide the around part.
Hello friends, still me, have some question.
I want to show a photo in my page, the DIV layer is 500 * 500px. I will replace the picture very often , the picture size is not sure, may be horizontal version may be vertical version, maybe 800*600px maybe 576*720px. I don't want to get the photo deformation. How to set CSS or JS, make the photo show only the center 500 * 500 px, hide the around part.
Thanks.
Started: September 21, 2011 Latest Activity: September 21, 2011 picturecenter

Thanks, friends. I'm so lack of imagination. Use a picture as a background image on this DIV is a good method.
September 21, 2011

3 Answers
Use a background image on a DIV with pre-defined dimensions, and set the image position to 50%, which essentially centers it. Whatever overflows the 500x500 will be cropped...
#yourImageDiv {
  background: url(../img/image.jpg) no-repeat 50%;
  height: 500px;
  width: 500px;
}

Posted: Go
In: September 21, 2011

One nice trick is to use a transparent PNG instead of a div and apply a background-image style to it. That way you get to use the image as you normally would (inline, etc.) but can crop at will.
#cropper {
  width: 500px;
  height: 500px;
  background-image: url(myBackgroundImage.png);
  background-repeat: no-repeat;
  background-position: center center;
}
and
<img id="cropper" src="clear.png">

Posted: Gamal
In: September 21, 2011

there is many ways, you can make it as a div background or you can use the CSS clip Property as:
<html>
<head>
<style type="text/css">
img 
{
position:absolute;
clip:rect(0px,60px,200px,0px);
}
</style>
</head>

<body>
<img src="img.gif" width="100" height="140" />
</body>
</html>

Posted: MacOS
In: September 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer