2013-05-29 31 views
0

使梯形我想打一个梯形填充画面,就像这样:从图像

Example

我不需要旋转。我不需要倾斜图片。 transform: matrix不起作用!

解决方案几乎只找到需要的两段代码连接:

background-image:url("http://3.bp.blogspot.com/-D9i-wqTIjFw/T5x_51p2rJI/AAAAAAAABLs/VytuZcJGNuY/s400/indahnya.jpg"); 

这一良好代码:

.myShape { 
width: 0; 
height: 50px; 
border-left: 50px solid red; 
border-top: 20px solid transparent; 
border-bottom: 20px solid transparent; 

}

+1

我不认为这是可能的2D变换;你需要'rotateY'的视角。 – Ryan

+1

例如,http://codepen.io/minitech/pen/GbDHn。你可以对任何图像做同样的事情。 – Ryan

+0

或者你是说你只是想将图像裁剪成梯形区域? – Ryan

回答

2

使用CSS,你可以做出这样的形状。尝试是这样的:

.myShape { 
    width: 0; 
    height: 50px; 
    border-left: 50px solid red; 
    border-top: 20px solid transparent; 
    border-bottom: 20px solid transparent; 
} 

jsFiddle Demo

+0

好的。只是litlle细节:如何添加它的工作属性:background-image:url(“http://3.bp.blogspot.com/-D9i-wqTIjFw/T5x_51p2rJI/AAAAAAAABLs/VytuZcJGNuY/s400/indahnya.jpg”); –

1

我知道这样做有一个图像是使用3D借助透视变换的唯一途径。所以,你的元素,你需要给它在y轴的旋转:

#rectangle { 
    background-image: url("http://3.bp.blogspot.com/-D9i-wqTIjFw/T5x_51p2rJI/AAAAAAAABLs/VytuZcJGNuY/s400/indahnya.jpg"); 
    -webkit-transform: rotateY(45deg); 
      transform: rotateY(45deg); 
} 

然后给的perspective一定的参考价值父。

Here's a demo!

+0

没关系。但不适用于Opera! –

+0

@JonMaximys:直到15.0。你无能为力,真的...... – Ryan