If you specify a 100% size for your image.
Your image will then take 100% of its container.
The thing you want is keeping your file at its original size, so do not specify any size for your image.
overflow:hidden
is the key to show only a part of your image.
If you want to always have the center of your image visible, you should take a look at this CSS3 property transform:translate(-50%,-50%)
with a proper positioning.
Take a look at this jsfiddle and tell me if it can help you.
Edit: With 2020 modern browser, it may be useful to take a look at the CSS object-fit
property. In particular object-fit: cover;
. Take a look at this updated jsfiddle.
.imageParent, .imageParentCover {
position: relative;
text-align: center;
width: 200px;
height: 200px;
overflow: hidden;
}
/* Solution using `transform: translate`: */
.imageParent img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
/* Solution using `object-fit: cover`: */
.imageParentCover img {
object-fit: cover;
width: 100%;
height: 100%;
}
Solution using <code>transform: translate</code>:
<div class="imageParent">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/640px-Google_2015_logo.svg.png" />
</div>
<hr />
Solution using <code>object-fit: cover</code>:
<div class="imageParentCover">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/640px-Google_2015_logo.svg.png" />
</div>