css - Child elements changing opacity with parent Image -
i have <div> element has background image. on top of have text hidden when user hovers on <div> element text show , <div> opacity lower. problem when hover on div elements inside change opacity well. have looked through stackoverflow see if has same problem found answers had rgba using background colors (not images).
here css:
.pic{ background-image:url(http://www.granitesportsinstitute.com/wp-content/uploads/2014/06/green-sea-turtle-150x150.jpg); -webkit-transition: .3s ease-in-out; -moz-transition: .3s ease-in-out; -o-transition: .3s ease-in-out; transition: .3s ease-in-out; } .textstuff{ visibility:hidden; } .pic:hover .textstuff{ visibility:visible; color:black; } .pic:hover{ filter: alpha(opacity=30); -moz-opacity: 0.3; -khtml-opacity: 0.3; opacity: 0.3; } html here:
<div class="pic" style="height:150px;width:150px;"> <div class="textstuff">this text</div> </div>
i able working wrapping , setting .pic position absolute. way fills background doesn't affect text:
<div class="wrapper"> <div class="pic"></div> <div class="textstuff"> <p>this textstuff</p> </div> </div> css code:
.wrapper { position: relative; } .pic { background-image:url(http://www.granitesportsinstitute.com/wp-content/uploads/2014/06/green-sea-turtle-150x150.jpg); width: 100%; height: 100%; position: absolute; -webkit-transition: .3s ease-in-out; -moz-transition: .3s ease-in-out; -o-transition: .3s ease-in-out; transition: .3s ease-in-out; } .textstuff { visibility:hidden; } .pic:hover ~ .textstuff { visibility:visible; color:black; } .pic:hover { opacity: 0.3; -moz-opacity: 0.3; -khtml-opacity: 0.3; opacity: 0.3; } here fiddle showing example:
Comments
Post a Comment