我想我的圖片看起來像以下:圖像不透明度爲1,CSS
圖像的底部是透明的,它越來越不透明度1. 頂我可以做這個效果一種顏色,帶線性漸變:
-webkit-linear-gradient(black, transparent);
但是圖片也可以嗎?
我想我的圖片看起來像以下:圖像不透明度爲1,CSS
圖像的底部是透明的,它越來越不透明度1. 頂我可以做這個效果一種顏色,帶線性漸變:
-webkit-linear-gradient(black, transparent);
但是圖片也可以嗎?
我知道的最新和最酷的方式是使用HTML 5掩碼。
它是這樣的:
CSS:
.masked
{
mask: url(#m1);
}
HTML 5:
<svg width="0" height="0">
<defs>
<linearGradient id="gradient" x1="0" y1="0" x2 ="0" y2="100%">
<stop stop-color="white" offset="0"/>
<stop stop-color="black" offset="1"/>
</linearGradient>
<mask id="masking" maskUnits="objectBoundingBox" maskContentUnits="objectBoundingBox">
<rect y="0.1" width="1" height="0.9" fill="url(#gradient)" />
</mask>
</defs>
</svg>
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="350">
<image xlink:href="http://upload.wikimedia.org/wikipedia/commons/4/4d/Iss007e10807_darker.jpg"
width="500" height="350" class="masked"></image>
</svg>
對於進一步閱讀:
先謝謝你。但是現在我必須刪除每一行以查看它的功能,以及它的工作原理。 ^^ –
這只是一個例子。花10分鐘時間閱讀有關內容並查看現場示例。這並不複雜。 – Itay
哦,我看到你剛從網站sry發佈的例子 –
我與CSS :)
Codepen例如嘗試:http://cdpn.io/hzBav
CSS(更新與淡出)
figure {
display: inline-block;
position: relative;
}
.overlay {
display: block;
height: 300px;
position: absolute;
width: 300px;
background-image: -moz-linear-gradient(
rgba(0, 0, 0, 0.8) 0%, rgba(255, 255, 255, 0) 85%
);
}
.overlay:after {
content: '';
display: block;
height: 300px;
width: 300px;
background-image: -moz-linear-gradient(
rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 100%
);
}
HTML基於評論
<figure>
<div class='overlay'></div>
<img src='http://placekitten.com/300/300' />
</figure>
更新。
圖片背後是什麼? –
使用具有透明度的靜態PNG,還是需要動畫? – Jonathan
什麼都沒有一個JavaScript和畫布不會修復。 – enhzflep