2017-07-31 98 views
0

这里有问题。我有一个完美的偏斜的div,但现在我希望图像适合它没有平铺,如果任何人都可以帮助,这将是很棒的。歪斜的div中的背景图片

我要为这样的: enter image description here

到目前为止我有这样的: enter image description here

HTML

<div class="box"></div> 

CSS

.box { 
position:relative; 
width:100%; 
height:500px; 
background: url(../images/clouds.jpeg); 
background-size:contain; 
padding:10px; 
margin-bottom:100px; 

}

.box:after { 
position:absolute; 
content:''; 
width:100%; 
height:100%; 
top:0; 
left:0; 
right:0; 
background:inherit; 
background-size:contain; 
transform-origin: top left; 
transform:skewY(10deg); 
z-index: -1; 

}

+0

如何使白色的角落作为单独的倾斜的div覆盖nonskewed的div与图像背景? –

回答

2

您应该使用background-size: cover,如果你想在img充满整个容器,然后用background-repeat: no-repeat有一个图像。

类似的东西应该工作:

.box { 
    position:relative; 
    width:100%; 
    height:500px; 
    background: url(../images/clouds.jpeg); 
    background-size:cover; 
    background-repeat: no-repeat; 
    padding:10px; 
    margin-bottom:100px; 
} 
0

这种形象不歪斜..

div{ 
 
display:inline-block; 
 
\t margin:10px; 
 
\t postion:relative; 
 
\t width:100px; 
 
\t height:100px; 
 
\t background:cyan; 
 
} 
 

 
div.covered{ 
 
background: 
 
\t linear-gradient(20deg,white,white,40px,transparent 40px,transparent),cyan; 
 
}
<div> 
 
normal 
 
</div> 
 
<div class="covered"> 
 
covered 
 
</div>

左下部分可以通过覆盖白色的彩色图像进行倾斜的线性渐变。

+0

因此,我设法通过使用剪切路径来获得我想要的结果。下一部分将覆盖容器顶部的下一个图像 – MBarton

+0

关闭此问题..upvote接受如果有任何答案值得..一个新的问题..你会得到很多资源放置在另一个顶部的一些元素。 – amit77309