2016-12-28 118 views
2

例如,我有這樣一個圖: Default imageCSS3彎曲/透視效果

我需要使它像與CSS3。在頂部有一種透視圖(區域標有紅色邊框): Image with perspective

是否有可能僅使用1圖像和CSS3樣式來製作這樣的效果?

+0

您應該使用這個工作,怎麼樣使用投影預先存在像d3.js這樣的庫?它有各種預測幫助你解決極地地區周圍扭曲的土地面積問題。純粹的CSS修復只是一種解決方法和解決方案。 – Terry

回答

2

我已經設置了一個div作爲背景圖片。

在僞元素上,具有相同的背景,並且此僞元素具有旋轉和透視的變換。

另一個僞,在相同的位置,以掩蓋原始圖像的上半部分

.test { 
 
    width: 600px; 
 
    height: 230px; 
 
    border: solid 1px red; 
 
    background-image: url(https://i.stack.imgur.com/wQ1Bp.png); 
 
    background-size: 600px 230px; 
 
    position: relative; 
 
} 
 
.test:after, 
 
.test:before { 
 
    content: ""; 
 
    width: 100%; 
 
    height: 30%; 
 
    top: 0px; 
 
    position: absolute; 
 
} 
 
.test:before { 
 
    background-color: white; 
 
} 
 
.test:after { 
 
    background-image: inherit; 
 
    background-size: inherit; 
 
    border: solid 1px green; 
 
    transform: perspective(400px) rotateX(50deg); 
 
    transform-origin: center bottom; 
 
}
<div class="test"></div>