javascript - Background-Only Opacity -
i have trouble css.
i have code (example):
<div class="background" style="background: url(sample.jpg) no-repeat;"> <div class="text-title">title</div> <div class="text">random stuff</div> </div> what want is, when hovering on background image - should opacity lets 0.3, how make it, inside items stay same opacity 1?
here's best trick in book. https://jsfiddle.net/xbxvr8as/
if have trouble css might bend brain jsfiddle pared down can it. play removing single styles see happens.
the crux relative:position element. can add "pretend" div-like thing using :after pseudo-element. give pseudo-element bunch of properties - important being position:absolute allows sit straight underneath text.
html
<div id="a"> stuff in here ..... </div> css
#a{position:relative} #a:after{ content:" "; position:absolute; display:block; top:0;left:0;right:0;bottom:0; background-color:#f00; z-index:-1; opacity:0.2; }
Comments
Post a Comment