1

I am trying to crop 50px from the top of an image. I am following the below reference but for some reason it didn't work in FF but worked in Chrome.

https://css-tricks.com/clipping-masking-css/

Html:

<img src="https://s30.postimg.org/lkqxmrk29/about.jpg" class="rectshape">

Demo:https://jsfiddle.net/squidraj/a4j343hg/1/

Any help is highly appreciated.

10
  • 1
    fiddle is working!! Whats the question? Commented Jan 19, 2017 at 13:47
  • 1
    This works good for me! Maybe you are using browser that not support clip property? Commented Jan 19, 2017 at 13:48
  • 1
    It looks working on jsfiddle. Commented Jan 19, 2017 at 13:48
  • 1
    are you using Firefox ? Commented Jan 19, 2017 at 13:49
  • 1
    caniuse.com/#feat=css-clip-path Commented Jan 19, 2017 at 13:49

1 Answer 1

4

Since the clip path is not supported very well, why not use overflow: hidden and a container element? Here is your updated JSFiddle demonstrating this. A negative margin can be used to hide part of the image. Cropping the image from other sides can be accomplished easily by using negative margin on the other sides. Only if you want a non-rectangular clipping path, you will have to resort to the SVG clipPath that was referred to in the comments. Example Fiddle.

.rectshape {
  overflow: hidden;
  margin: 5px;
  border: 1px solid #000;
}

.rectshape > img {
  margin-top: -50px;
  border: 1px solid #00f;
}
<div class="rectshape">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a">
</div>
<div class="rectshape">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a">
</div>
<div class="rectshape">
  <img src="https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a">
</div>

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

3 Comments

Thanks for this concept.. Actually I have few images stacked one below another so it's bit difficult to use negative margin.
The negative margin is only applied to the image, it does not extend to the container. I will update my answer to include stacked images.
Brilliant. Thanks a lot for your help.

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.