html - CSS button hover background style child -
when hovers on button img element inside it, should have red background color.
<button class="btn-img"> <img src="http://upload.wikimedia.org/wikipedia/en/thumb/2/2a/burj_al_arab,_dubai,_by_joi_ito_dec2007.jpg/220px-burj_al_arab,_dubai,_by_joi_ito_dec2007.jpg" alt="dubai" /> </button> .btn-img { display: block; width: 160px; height: 120px; margin: 0; padding: 0; border: 0; cursor: pointer; } .btn-img:hover { background-color: red; } .btn-img:hover img { background-color: blue; } is possible? because of button element, because if child inside div has background color, , parent background color changes, overwrites children's background color.
here 1 possible way of getting effect want:
<button class="btn-img"> <div class="img-wrap"> <img src="image_name.jpg" /> </div> </button> and css might like:
.btn-img { display: block; margin: 0; padding: 0; border: 0; cursor: pointer; background-color: white; outline: 1px dotted blue; } .btn-img .img-wrap { margin: 10px; } .btn-img img { display: block; } .btn-img:hover .img-wrap { background-color: black; } .btn-img:hover img { opacity: 0.8; } how works
wrap image <div> can control margins , padding more accurately , give hook control background color behind image without having color spill outside of image itself.
when trigger .btn-img:hover, change background color of div.img-wrap black , change opacity of image 0.8. has effect of darkening image.
you can experiment effect trying different background colors image wrap element , degree of opacity.
i think might work in ie7, give try.
fiddle: http://jsfiddle.net/audetwebdesign/8qmtv/
and way...
if wrapping image link use javascript type of zoom-view effect (highslider example), can replace <div class="img-wrap"> simple <a> tag , set display: block.
keep in mind...
browsers tend style <button> differently other inline elements <span>, properties margin , padding may behave bit differently might expect.
Comments
Post a Comment