html - Making Image Overlay more responsive? -
is there way of making overlay more responsive? in, making overlay not cut off words, or go outside image when resolution changes?
to further clarify: having 3 images next each other in row, per w3css framework using, 3 images under that, etc. each image has overlay text links direct other pages, shown in example below. issue responsiveness. want images, , overlays, responsive screen size changes , resolution.
thank you!
.container { position: relative; width: 50%; } .image { display: block; width: 100%; height: auto; } .overlay { position: absolute; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: .5s ease; background-color: #008cba; } .container:hover .overlay { opacity: 1; } .text { color: white; font-size: 15px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); }
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/> <div class="w3-row-padding"> <div class="w3-third w3-container w3-margin-bottom"> <div class="container"> <img src="https://www.google.com/images/branding/product/ico/googleg_lodp.ico" alt="google" style="height:300px;width:400px" class="w3-hover-opacity"> <div class="overlay"> <div class="text"> <a href="https://www.google.com">google sample1</a><br> <a href="https://www.google.com">googlesample2</a><br> </div> </div> </div> <div class="w3-container w3-white" style="height:50px;width:400px"> <h3>example 1</h3> </div> </div> </div>
to make sure, image
same width parent, better use not width = 100%
property, min-width = 100%
, max-width = 100%
too. if want keep dimensions of image
, should point height = auto
, in case should height = auto !important
. , breaking long words in overlay
, have added following rules:
overflow-wrap: break-word; word-wrap: break-word; word-break: break-all; word-break: break-word; hyphens: auto;
here working snippet:
.container { position: relative; width: 50%; } .image { display: block; width: 100%; min-width: 100%; max-width: 100%; height: auto !important; } .overlay { position: absolute; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: .5s ease; background-color: #008cba; overflow-wrap: break-word; word-wrap: break-word; word-break: break-all; word-break: break-word; hyphens: auto; } .container:hover .overlay { opacity: 1; } .text { color: white; font-size: 15px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); }
<div class="w3-row-padding"> <div class="w3-third w3-container w3-margin-bottom"> <div class="container"> <img src="https://www.google.com/images/branding/product/ico/googleg_lodp.ico" alt="google" style="height:300px;width:400px" class="w3-hover-opacity image"></a> <div class="overlay"> <div class="text"> <a href="https://www.google.com">google sample1</a><br> <a href="https://www.google.com">googlesample2</a><br> </div> </div> </div> <div class="w3-container w3-white" style="height:50px;width:400px"> <h3>example 1</h3> </div> </div>
Comments
Post a Comment