2016-09-15 3 views
0

이미지에 tinted-image 클래스가있을 때마다 투명한 빨간색 오버레이를 추가하려고합니다. CSS로 처리하려고합니다. 사실, 직접 적용하려면 img 태그를 사용하고 싶습니다. 이것이 가능한가?CSS로 이미지의 색상 레이어를 오버레이합니다

<img class="tinted-image" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg"></img> 

그리고 CSS :

My JS fiddle

나는이 시도

.tinted-image { 

    background: 
    /* top, transparent red */ 
    linear-gradient(
     rgba(0, 255, 0, 0.45), 
     rgba(0, 255, 0, 0.45) 
    ) 

} 

을 그리고 아무 일도 발생하지 않습니다.

아래처럼 div를 사용하고 싶지 않습니다. 내가 직접 img 태그에서 구현하려고합니다.

<div class="tinted-div"></div> 
.tinted-div { 
    width:200px; 
    height:200px; 
    background: 
    /* top, transparent red */ 
    linear-gradient(
     rgba(0, 255, 0, 0.45), 
     rgba(0, 255, 0, 0.45) 
    ), 
    /* bottom, image */ 
    url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg); 
} 

누군가 도와주세요. :(

+0

가능한 중복 http://stackoverflow.com/questions/12546499/tint-image-using-css-without-overlay) –

답변

0

당신은 사용하여 비슷한 효과를 얻을 수 있습니다 :이 도움이 후 경우

.overlay { 
 
    position: relative; 
 
    overflow: hidden; 
 
} 
 
.overlay:after { 
 
    content: ''; 
 
    position: absolute; 
 
    width: inherit; 
 
    height: inherit; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    background: rgba(0, 255, 0, 0.5); 
 
}
<div class="overlay"> 
 
    <a href="#"> 
 
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/owl1.jpg"> 
 
    </a> 
 
</div>

[오버레이없이 CSS를 사용하여 색조 이미지 (의
+0

오버레이 div를 사용하지 않고도 @abokuro는 가능합니까? –

+0

도와주세요 :( –

+1

그냥 CSS를 사용하는 것이 가능하지 않다고 생각합니다. http://stackoverflow.com/questions/18322548/black-transparent-overlay-on-image-hover-with-only-css – sol

관련 문제