Goal:
Mouse hovering over the picture and its area, the title and content will raise up.
The contents background and height should go to the bottom of the area.
Problem:
The title and contents background don't go all the way down to the button.
I don't know how to do.
Please take a look at the picture for visual communication.
JSBin:
https://jsbin.com/xenavotemu/edit?html,output
Thank you!
.cards {
margin: 0 auto;
display: grid;
grid-gap: 5px;
}
.card {
width: 100%;
min-height: 100px;
background-color: #e6e6e6;
text-align: center;
border: 1px solid white;
transition: border 1s;
position: relative;
}
.card:hover {
border: 1px solid black;
}
.card .wrapper {
bottom: 0;
position: absolute;
transition: all .3s ease;
width: 100%;
}
.card:hover .wrapper {
bottom: 30px;
transform: translateY(-50%)
}
.cardTitle {
width: 100%;
margin-top: -4px;
color: white;
background-color: grey;
font-size: xx-large;
}
.cardText {
background-color: #fff;
height: 0;
opacity: 0;
visibility: hidden;
}
.card:hover .cardText {
height: 100%;
;
opacity: 1;
visibility: visible;
}
.responsive {
width: 300px;
}
/* 2 column */
#media (min-width: 700px) and (max-width: 899px) {
div.cards {
grid-template-columns: repeat(2, 1fr);
}
}
/* 3 columns */
#media (min-width: 900px) {
div.cards {
grid-template-columns: repeat(3, 1fr);
}
}
<div class="cards">
<div class="card">
<img src="https://dogtowndogtraining.com/wp-content/uploads/2012/06/300x300-061-e1340955308953.jpg" class="responsive" alt="" />
<div class="wrapper">
<div class="cardTitle">ONE</div>
<div class="cardText">aaa<br /> aaaa</div>
</div>
</div>
<div class="card">
<img src="https://dogtowndogtraining.com/wp-content/uploads/2012/06/300x300-061-e1340955308953.jpg" class="responsive" alt="" />
<div class="wrapper">
<div class="cardTitle">ONE</div>
<div class="cardText">aaa<br /> aaa<br /> aaa</div>
</div>
</div>
<div class="card">
<img src="https://dogtowndogtraining.com/wp-content/uploads/2012/06/300x300-061-e1340955308953.jpg" class="responsive" alt="" />
<div class="wrapper">
<div class="cardTitle">ONE</div>
<div class="cardText">aaa<br /> aaa<br /> aaa<br /> aaa</div>
</div>
</div>
</div>
Using the technic from this answer:
https://stackoverflow.com/a/8331169/10839134
Removed following style because it's causing the height problem.
.card:hover .wrapper {
bottom: 30px;
transform: translateY(-50%);
}
Instead of changing the visibility on .cardText I change the max-height:
.cardText {
background-color: #fff;
height: 0;
opacity: 0;
max-height: 0;
}
.card:hover .cardText {
height: 100%;
opacity: 1;
max-height: 500px;
transition: max-height 0.25s ease-in;
}
https://jsbin.com/xowematuki/1/edit?html,css,js,output
The idea is to put the image inside it's own wrapper that will shrink from the bottom up (from 100% to 70% in this example). Of course, all overflow hidden.
.cards {
margin: 0 auto;
display: grid;
grid-gap: 5px;
}
.card {
width: 100%;
min-height: 100px;
background-color: #e6e6e6;
text-align: center;
border: 1px solid white;
transition: border 1s;
position: relative;
}
.card:hover {
border: 1px solid black;
}
.card .wrapper {
bottom: 0;
position: absolute;
transition: all .3s ease;
width: 100%;
}
.card:hover .wrapper {
bottom: 30px;
transform: translateY(-50%)
}
.cardTitle {
width: 100%;
margin-top: -4px;
color: white;
background-color: grey;
font-size: xx-large;
}
.cardText {
background-color: #fff;
height: 0;
opacity: 0;
visibility: hidden;
}
.card:hover .cardText {
height: 100%;
opacity: 1;
visibility: visible;
}
.responsive {
width: 300px;
}
.img-wrapper {
height: 100%;
position: relative;
overflow: hidden;
transition: all .3s ease;
}
.card:hover .img-wrapper {
height: 70%;
}
.card {
overflow: hidden;
}
<div class="cards">
<div class="card">
<div class="img-wrapper">
<img src="https://dogtowndogtraining.com/wp-content/uploads/2012/06/300x300-061-e1340955308953.jpg" class="responsive" alt="" />
</div>
<div class="wrapper">
<div class="cardTitle">ONE</div>
<div class="cardText">aaa<br /> aaaa</div>
</div>
</div>
</div>
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to shrink upload-container and img-vector when the screen size is reduced but it seems that the upload container is not shrinking in size. I am new to CSS and I am unable to figure out the problem.
Link to my pen
body,
#main-container,
.upload-container,
.drop-zone {
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
body,
.upload-container,
.drop-zone {
flex-direction: column;
}
#main-container {
background-color: green;
justify-content:space-around;
width: 100%;
margin: auto;
}
.image-vector {
width: 50vw;
height: 50vh;
flex-shrink: 1;
background: url(https://picsum.photos/200) no-repeat center;
background-size: contain;
}
.upload-container {
background: #17191c;
border-radius: 25px;
flex-shrink: 1;
}
I just added the following code in Responsive Mode. With flex-flow: row wrap; I changed the flex-direction to row and flex-warp to warp break in overflow mode.
#main-container,
.upload-container,
.drop-zone {
flex-flow: row wrap;
}
:root {
--main-bg-color: #212429;
--light-blue: #3a9aed;
--border-color: #3a9aed;
--container-width: 500px;
}
* {
margin: 0px;
padding: 0px;
}
body {
font-family: system-ui;
background: var(--main-bg-color);
height: 98vh;
overflow: hidden;
color: white;
}
body,
#main-container,
.upload-container,
.drop-zone {
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
body,
.upload-container,
.drop-zone {
flex-direction: column;
}
.header-container {
position: absolute;
top: 4%;
font-family: Cambria, Cochin, Georgia, Times, "Times New Roman", serif;
font-size: 55px;
}
#main-container {
background-color: green;
/* justify-content:space-around; */
width: 100%;
margin: auto;
}
.footer-container {
position: absolute;
top: 2%;
left: 80%;
}
.image-vector {
width: 50vw;
height: 50vh;
flex-shrink: 1;
background: url(https://picsum.photos/200) no-repeat center;
background-size: contain;
}
.upload-container {
background: #17191c;
border-radius: 25px;
flex-shrink: 1;
}
.drop-zone {
width: var(--container-width);
min-height: 200px;
border: 2px dashed var(--border-color);
border-radius: 10px;
margin: 30px;
transition: 0.2s all ease-in;
}
/* will be added when user drags */
.drop-zone.dragged {
background: var(--main-bg-color);
border-color: #0288d1;
}
.drop-zone input {
display: none;
}
.icon-container {
position: relative;
width: 75px;
height: 100px;
}
.icon-container img {
width: 75px;
position: absolute;
transition: transform 0.25s ease-in-out;
transform-origin: bottom;
}
.icon-container .center {
z-index: 10;
}
.icon-container .right,
.icon-container .left {
filter: grayscale(0.5);
transform: scale(0.9);
}
.dragged .center {
transform: translateY(-5px);
}
.dragged .right {
transform: rotate(10deg) scale(0.9) translateX(20px);
}
.dragged .left {
transform: rotate(-10deg) scale(0.9) translateX(-20px);
}
.title {
font-size: large;
}
#browseBtn {
color: #2196f3;
cursor: pointer;
}
/* uploading progress styles */
.progress-container {
border: 2px solid var(--main-bg-color);
width: var(--container-width);
height: 70px;
border-radius: 10px;
margin-bottom: 25px;
position: relative;
display: none;
}
.progress-container .inner-container {
margin: 10px 15px;
z-index: 2;
position: absolute;
width: calc(100% - 30px);
}
.progress-container .percent-container {
font-size: 14px;
margin: 5px;
opacity: 0.7;
}
.progress-container .bg-progress {
position: absolute;
background: var(--main-bg-color);
width: 100%;
height: 100%;
z-index: 1;
transition: transform 250ms linear;
transform: scaleX(0);
transform-origin: left;
}
.progress-container .progress-bar {
width: 100%;
height: 3px;
border-radius: 2px;
background: #03a9f4;
transition: transform 200ms linear;
transform: scaleX(0);
transform-origin: left;
}
/* sharing container style */
.sharing-container {
margin-bottom: 25px;
width: var(--container-width);
border-radius: 10px;
display: none;
}
.sharing-container p {
text-align: center;
}
.sharing-container .expire {
font-size: 16px;
opacity: 0.7;
margin-top: 0;
}
.sharing-container .input-container {
display: flex;
position: relative;
width: 100%;
margin-bottom: 20px;
}
.sharing-container .input-container input {
width: 100%;
border-radius: 3px;
padding: 10px 15px;
font-size: 20px;
border: 2px dashed var(--border-color);
border-radius: 6px;
background: #17191c;
color: #ffffff;
}
.sharing-container img {
height: 22px;
width: 30px;
position: absolute;
right: 7px;
top: 12px;
cursor: pointer;
background: #17191c;
color: #ffffff;
}
.email-container form {
border: 2px solid var(--border-color);
width: 100%;
padding: 15px;
box-sizing: border-box;
border-radius: 10px;
display: flex;
flex-direction: column;
align-items: center;
}
.email-container,
.send-btn-container {
display: flex;
flex-direction: column;
align-items: center;
}
.email-container label {
margin: 5px;
font-size: 18px;
}
.email-container input {
border: none;
border-bottom: 2px solid var(--border-color);
height: 19px;
font-size: 18px;
text-align: center;
}
.email-container input:focus {
outline: none;
}
.email-container .filed {
margin-bottom: 5px;
display: flex;
justify-content: space-between;
width: 400px;
}
.send-btn-container button {
font-size: 18px;
padding: 8px 40px;
margin-top: 15px;
background: #3a9aed;
border: none;
border-radius: 5px;
color: #ffffff;
cursor: pointer;
}
.toast {
position: absolute;
bottom: 10px;
right: 50%;
transform: translate(50%, 60px);
padding: 10px 20px;
background: var(--light-blue);
color: #fff;
border-radius: 5px;
font-size: 18px;
box-shadow: 0px 10px 15px -3px rgba(0, 0, 0, 0.1),
0px 4px 6px -2px rgba(0, 0, 0, 0.05);
transition: transform ease-in-out 0.2s;
}
.image-vector {
background: url("https://picsum.photos/200") no-repeat center;
background-size: contain;
height: 50vh;
width: 50vw;
}
.show.toast {
transform: translate(50%, 0);
}
#media screen and (max-width: 900px) {
:root {
--container-width: 320px;
}
body,
#main-container,
.upload-container,
.drop-zone {
flex-flow: row wrap;
}
.email-container .filed {
flex-direction: column;
}
.email-container .filed {
width: 300px;
}
}
<div class="header-container">EZ Sharing</div>
<main id='main-container'>
<section class="upload-container">
<form action="">
<div class="drop-zone">
<div class="icon-container">
<img src="https://picsum.photos/200" draggable="false" class="center" alt="File Icon" />
<img src="https://picsum.photos/200" draggable="false" class="left" alt="File Icon" />
<img src="https://picsum.photos/200" draggable="false" class="right" alt="File Icon" />
</div>
<input type="file" id="fileInput" />
<div class="title">
Drop your Files here or,
<span id="browseBtn">Browse</span>
</div>
</div>
</form>
<div class="progress-container">
<div class="bg-progress"></div>
<div class="inner-container">
<div class="status">Uploading...</div>
<div class="percent-container">
<span class="percentage" id="progressPercent">0 %</span>
</div>
<div class="progress-bar"></div>
</div>
</div>
<div class="sharing-container">
<p class="expire">Link expires in 24 hrs</p>
<div class="input-container">
<input type="text" id="fileURL" readonly />
<img src="./copy-icon.svg" id="copyURLBtn" alt="copy to clipboard icon" />
</div>
<p class="email-info">Or Send via Email</p>
<div class="email-container">
<form id="emailForm">
<div class="filed">
<label for="fromEmail">Your email</label>
<input type="email" autocomplete="email" required name="from-email" id="fromEmail" />
</div>
<div class="filed">
<label for="toEmail">Receiver's email</label>
<input type="email" required autocomplete="receiver" name="to-email" id="toEmail" />
</div>
<div class="send-btn-container">
<button type="submit">Send</button>
</div>
</form>
</div>
</div>
</section>
<div class="image-vector"></div>
</main>
<div class="toast">Sample message</div>
<div class="footer-container">
<a href="" target="_blank">
<img border="0" alt="Facebook" src="./github-logo.svg" width="50" height="50" />
</a>
<a href="/" target="_blank">
<img border="0" alt="Facebook" src="./linkedin.svg" width="50" height="50" />
</a>
<a href="">
<img border="0" alt="Facebook" src="./facebook.svg" width="50" height="50" />
</a>
</div>
I have searched all over stack overflow but I am unable to find any clue and I am struck here. I used flex container and child items in my code to some extent but I couldn't move beyond that. Thing is when we hover a child item, a new child item need to be created as shown in the expected result. Should we need to use pseudo element or any other flex properties to achieve this. Thanks much in advance.
My code:
https://jsfiddle.net/k2qr398u/1/
My result
https://imgur.com/kRHNHuu
Expected result:
https://imgur.com/2B6CkYF
/**CSS**/
body {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
background-color: #400017;
}
.img-css {
width: 50px;
height: 50px;
}
.main-heading {
display: block;
text-align: center;
color: #fc065d;
margin-bottom: 70px;
}
.img-js {
width: 50px;
height: 50px;
}
.container {
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
border: 3px solid #360310;
max-width: 610px;
height: 310px;
text-align: center;
margin: 0 auto;
flex-direction: row;
/* transform: translate(-50%,-50%); */
}
.col {
width: 130px;
height: 100px;
margin: 0 auto;
border: 3px solid #5e0a1f;
padding-top: 44px;
padding-left: 26px;
padding-right: 26px;
color: #fff;
background-color: #010001;
border-radius: 30px;
z-index: 20;
/* position: relative; */
}
.col p {
font-size: 16px;
font-weight: bold;
}
.col-2 p {
position: relative;
top: 55px;
text-align: center;
font-weight: bold;
}
<!--**HTML**-->
<body>
<div class="container">
<div class="col col-1">
<img src="images/css.svg" alt="CSS logo" class="img-css">
<br>
<p>I am</p>
</div>
<div class="col col-2">
<p class="my-name">Sri</p>
</div>
<div class="col col-3">
<img src="images/javascript.svg" alt="JS logo" class="img-js">
<p>Developer
</p>
</div>
</div>
</body>
P.S: Sorry if this question sounds very silly or dumb, I am a beginner trying to learn web dev skillsets.
I have created something similar to your expected result. Please run the code snippet for the result.
UPDATE: To include the hover off transition.
/**CSS**/
body {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
background-color: #400017;
}
.img-css {
width: 50px;
height: 50px;
}
.main-heading {
display: block;
text-align: center;
color: #fc065d;
margin-bottom: 70px;
}
.img-js {
width: 50px;
height: 50px;
}
.container {
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap: wrap;
border: 3px solid #360310;
max-width: 610px;
height: 310px;
text-align: center;
margin: 0 auto;
flex-direction: row;
/* transform: translate(-50%,-50%); */
}
.col {
width: 130px;
height: 100px;
margin: 0 auto;
border: 3px solid #5e0a1f;
padding-top: 44px;
padding-left: 26px;
padding-right: 26px;
color: #fff;
background-color: #010001;
border-radius: 30px;
z-index: 20;
position: relative;
}
.col p {
font-size: 16px;
font-weight: bold;
}
/*
.col-2 p {
position: relative;
top: 55px;
text-align: center;
font-weight: bold;
}
*/
.col-1,
.col-2-1,
.col-2-2,
.col-3 {
position: absolute;
left: 0;
top: 0;
transition: 1s;
}
.wrapper {
position: relative;
}
.wrapper:hover .col-1 {
transition: 1s;
left: -200px;
}
.wrapper:hover .col-2-1 {
transition: 1s;
top: -170px;
}
.wrapper:hover .col-2-2 {
transition: 1s;
top: 170px;
}
.wrapper:hover .col-3 {
transition: 1s;
left: 200px;
}
<!--**HTML**-->
<body>
<div class="container">
<div class="wrapper">
<div class="col"> Underneath</div>
<div class="col col-1">
<img src="images/css.svg" alt="CSS logo" class="img-css">
<br>
<p>I am</p>
</div>
</div>
<div class="wrapper">
<div class="col"> Underneath</div>
<div class="col col-2-1">
<p class="my-name">Sri</p>
</div>
<div class="col col-2-2">
<p class="my-name">Pratham</p>
</div>
</div>
<div class="wrapper">
<div class="col"> Underneath</div>
<div class="col col-3">
<img src="images/javascript.svg" alt="JS logo" class="img-js">
<p>Developer
</p>
</div>
</div>
</div>
</body>
The idea is:
Overlay some content over main content.
On hover reveal it :)
.card {
width: 150px;
height: 80px;
border: 1px solid #999;
background: #ccc;
border-radius: 8px;
position: relative;
margin: 20% auto;
}
.card:hover > .o-top {
top: -80px;
background: #f00;
}
.card:hover > .o-bottom {
bottom: -80px;
}
.o-top {
top: 0;
transition: top 1.5s, background 2s;
}
.o-bottom {
bottom: 0;
transition: bottom 1.5s, background 2s;
}
.card-overlay {
position: absolute;
height: 100%;
width: 100%;
background: #333;
pointer-events: none;
color: #fff;
}
<div class="card">
<div class="card-overlay o-top">TOP OVERLAY</div>
<div class="card-overlay o-bottom">BOTTOM OVERLAY</div>
<H3>INTERNAL CONTENT</H3>
</div>
<div align="center">
<div class="container2">
<img src="img/3.png" alt="discussion Threads" class="image" height="200px" width="150px">
<div class="overlay">
<div class="text">Here you can discuss different topics and ask or answer questions.</div>
</div>
</div>
<div class="container2">
<img src="download.png" alt="Avatar" class="image">
<div class="overlay overlay2">
<div class="text">Bottom</div>
</div>
</div>
<div class="container2">
<img src="download.png" alt="Avatar" class="image">
<div class="overlay overlay3">
<div class="text">Bottom</div>
</div>
</div>
</div>
i want to make the images next to each other but i can't idk why or how tbh and this is the css i have tried everything it doesn't work
I want 3 images side by side with hover and caption, at the moment I have 3 images going from top to bottom, the hover is good but not side by side. How do I make the images appear side by side? Thanks.
.container2 {
position: relative;
width: 250px;
}
.image {
display: block;
width: 250px;
height: 300px;
height: auto;
margin: 17%;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay {
height: 85%;
}
.text {
color: white;
font-size: 15px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.overlay2 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay2 {
height: 85%;
}
.overlay3 {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #4CAF50;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
margin-left: 17%;
border-top-left-radius: 70px;
border-top-right-radius: 70px;
pointer-events: none
}
.container2:hover .overlay3 {
height: 85%;
}
You would have to add float property to your container2 selector. Please check the css rule below.
.container2 {
float: left;
position: relative;
width: 250px;
}
.container {
width: 400px;
height: 400px;
padding: 0px;
display: grid;
grid-template-columns: auto auto auto;
}
.item {
width: 100px;
height: 200px;
margin: 2px;
}
<div class="container">
<div class="item" style="background-color:red">
</div>
<div class="item" style="background-color:blue">
</div>
<div class="item" style="background-color:yellow">
</div>
</div>
Why don't you grid-display property ?
This might help you
For these such scenarios there is a beautiful/clean/simple concept called flex which is helping by decreasing number of lines of code:
here is the example with column, color and hover effect, hope it helps you:
#MainDiv {
height: 200px;
width: 650px;
display: flex;
/* here is a concept */
flex-direction: row;
/* you can either change it to row/columns */
padding: 5px;
}
#firstDiv {
width: 200px;
margin: 5px;
background-color: red;
}
#secondDiv {
width: 200px;
margin: 5px;
background-color: blue;
}
#thirdDiv {
width: 200px;
margin: 5px;
background-color: green;
}
#firstDiv:hover {
background-color: blue;
color: white;
}
#secondDiv:hover {
background-color: green;
color: white;
}
#thirdDiv:hover {
background-color: red;
color: white;
}
<div id="MainDiv">
<div id="firstDiv">First Div</div>
<div id="secondDiv">Second Div</div>
<div id="thirdDiv">Third Div</div>
</div>
I'm trying to code a new featured artwork widget for my DeviantART and I'm having a little but of trouble working out how to get the buttons to hover individually, as they both highlight when only one is hovered over.
DeviantART's CSS syntax doesn't support div id's for whatever reason, so my only option is to use class selectors. This got me really stuck, as I've only ever done simple web design/layout. Any support would be greatly appreciated!
*The same image is used on both elements just to test them. The transition properties are for personal testing as well.
HTML:
<div class="container">
<img src="http://orig09.deviantart.net/410a/f/2017/122/0/0/vaporeon_by_nethartic-db7uyqc.png" class="img">
<div class="middle">
<div class="text">1</div>
</div>
<div class="container">
<img src="http://orig09.deviantart.net/410a/f/2017/122/0/0/vaporeon_by_nethartic-db7uyqc.png" class="img">
<div class="middle">
<div class="text">2</div>
</div>
CSS:
.container {
background-color: white;
position: relative;
margin: 0 auto;
width: 500px;
height: 80px;
}
.img {
background-color: white;
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
margin: 10px 0;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.container:hover .image {
opacity: 0.7;
}
.container:hover .middle {
opacity: 1;
background-color: transparent;
}
.text {
text-align: center;
background-color: #8b9fa6;
margin: 0 auto;
color: white;
font-size: 20px;
font-family: abel, sans-serif;
letter-spacing: 10px;
opacity: 1;
width: 500px;
}
You just missed to close your <div class="container"></div>. Otherwise your code works just fine
.container {
background-color: white;
position: relative;
margin: 0 auto;
width: 500px;
height: 80px;
}
.img {
background-color: white;
opacity: 1;
display: block;
width: 100%;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
margin: 10px 0;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.container:hover .image {
opacity: 0.7;
}
.container:hover .middle {
opacity: 1;
background-color: transparent;
}
.text {
text-align: center;
background-color: #8b9fa6;
margin: 0 auto;
color: white;
font-size: 20px;
font-family: abel, sans-serif;
letter-spacing: 10px;
opacity: 1;
width: 500px;
}
<div class="container">
<img src="http://orig09.deviantart.net/410a/f/2017/122/0/0/vaporeon_by_nethartic-db7uyqc.png" class="img">
<div class="middle">
<div class="text">1</div>
</div>
</div>
<div class="container">
<img src="http://orig09.deviantart.net/410a/f/2017/122/0/0/vaporeon_by_nethartic-db7uyqc.png" class="img">
<div class="middle">
<div class="text">2</div>
</div>
</div>
I'm trying to create some cards with a hover overlay effect on the image, but can't seem to get the overlay to fit the size of the image. Anyone got any ideas?
http://codepen.io/SRBET/pen/peXooX
Thanks for your 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; to the img.
.card img {
max-width: 100%;
max-height: 100%;
display:block;
}