2016-09-23 57 views
-8

如何在下面的图像上设置顶部和底部的渐变颜色?

顶部和底部有不透明度的颜色渐变,如何使图像在背景中?

+0

当然,你已经尝试过一些东西/研究这个。你发现了什么?为什么这不适合你? – PeeHaa

+1

预计您至少会尝试自己编写此代码。堆栈溢出不是代码写入服务。我建议你做一些[**额外的研究**](http://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) ,无论是通过谷歌或通过搜索,做出尝试和。如果您仍然遇到麻烦,请返回**您的代码**并解释您尝试过的以及为什么它不起作用。 –

回答

-1

有多种方式来获得这一点,但这里有一个与伪元素:

JSfiddle

body {padding: 0; margin: 0;} 
 

 
.imgholder { 
 
    position: relative; 
 
    display: inline-block; 
 
    line-height: 0; 
 
} 
 

 
.imgholder::before { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    pointer-events: none; 
 
    background: linear-gradient(rgba(40, 40, 40, 0.5), transparent 25%); 
 
} 
 

 
.imgholder::after { 
 
    content: ""; 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    pointer-events: none; 
 
    background: linear-gradient(0deg, rgba(40, 40, 40, 0.5), transparent 25%); 
 
}
<div class="imgholder"> 
 
<img src="http://www.greenleafown.tv/wp-content/themes/15zine/library/images/placeholders/placeholder-360x240.png" width="360" height="240"> 
 
</div>

相关问题