用CSS对角切割图像 [英] Cutting image diagonally with CSS

查看:102
本文介绍了用CSS对角切割图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CSS对角切掉一部分图像或容器?

需要切除的部分为三角形

The part that needs to be cut away has the form of a triangle

更具体地说:如果上面的图片是图片,则应切除蓝色部分,而不是黄色

To be more specific: if the above picture is the image the blue part should be cut out, not the yellow

html应为:

<figure>
 <img src="img_pulpit.jpg" alt="The Pulpit Rock">
</figure>

或:

<div class="container">
  content
</div>

根据我自己的调查,有很多方法可以做到这一点,但是大多数方法都是很棘手的,因此寻找一种最佳方法.

There is from my own investigation a lot of ways to do this, but most of them is hacky, so looking for a best approach

最低浏览器支持:IE11,最新的Webkit等.

Min browser support: IE11, latest webkits etc.

推荐答案

使用CSS3 -clip-pathpolygon这样.您可以指定任何路径.

Use CSS3 -clip-path and polygon like this. You can specify whatever path you want to.

img {
  width: 100px;
  height: 100px;
  -webkit-clip-path: polygon(0 0, 0 100px, 100px 80px, 100px 0);
  clip-path: polygon(0 0, 0 100px, 100px 80px, 100px 0);
}

<img src="https://picsum.photos/id/0/100/100">

http://jsfiddle.net/r3p9ph5k/

对于一些额外的内容,您可能想看看例如.另外,有关IE的更多信息,请参见.

For some extra bits you might want to take a look at e.g. this. Also, for more information about IE, see this.

这篇关于用CSS对角切割图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆