html - Creating a hover overlay on an image, but cant seem to make it correct size? -
i'm trying create cards hover overlay effect on image, can't seem overlay fit size of image. got ideas?
http://codepen.io/srbet/pen/pexoox
thanks help!
.flexwrapper { max-width: 1280px; margin: 0 auto; display: flex; flex-wrap: wrap; justify-content: center; } .card { display: flex; flex-direction: column; margin: 5px; max-width: 400px; height: auto; box-shadow: 1px 3px 16px -5px rgba(0,0,0,0.75); transition: 0.1s ease-in-out; } .card:hover { box-shadow: 1px 3px 16px 0px rgba(0,0,0,0.75); } .card img { max-width: 100%; max-height: 100%; } .overlaycontainer { position: relative; max-height: 100%; max-width: 100%; } .overlay { position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; background-color: rgba(0,0,0,0.5); opacity: 0; transition: 0.5s ease; } .overlay:hover { opacity: 1; } .overlaytext { color: white; position: absolute; left: 50%; top: 50%; margin-right: 50%; transform: translate(-50%, -50%); } .card h1 { font-size: 1rem; margin: 2.5px; padding-bottom: 5px; } .card p { margin: 2.5px; }
<div class="flexwrapper"> <div class="card"> <div class="overlaycontainer"> <div class="overlay"><h1 class="overlaytext">lorem ipsum</div> <img src="http://placehold.it/640x320"> </div> <h1>lorem ipsum</h1> <p>lorem ipsum dolor...</p> </div> <div class="card"> <div class="overlaycontainer"> <div class="overlay"><h1 class="overlaytext">lorem ipsum</h1></div> <img src="http://placehold.it/640x320"> </div> <h1>lorem ipsum</h1> <p>lorem ipsum dolor...</p> </div> </div>
add display:block; img.
.card img { max-width: 100%; max-height: 100%; display:block; }
Comments
Post a Comment