I am creating a div which will enclose a users name and when they hover over a profile image then it will display the name over the image, when I am doing this it does not center the div over the image solely which will be causing a problem when styling the website.
My CSS is below:
.miniProfileImage {
border-radius: 100%;
border: 3px dashed #28A745;
width: 100%;
max-width: 200px;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
opacity: 1;
display: block;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.img-container {
position: relative;
width: 50%;
}
.img-container:hover .miniProfileImage {
opacity: 0.3;
}
.img-container:hover .middle {
opacity: 1;
}
.middleText {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
A sample HTML mark-up can be seen here:
<div class='img-container'>
<img class='miniProfileImage' src='http://via.placeholder.com/500x500'>
<div class='middle'>
<p class='middleText'>Some Name</p>
</div>
</div>
I have also created a JS Fiddle to represent what is happening
.miniProfileImage {
border-radius: 100%;
border: 3px dashed #28A745;
width: 100%;
max-width: 200px;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
opacity: 1;
display: block;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.img-container {
position: relative;
width: 50%;
}
.img-container:hover .miniProfileImage {
opacity: 0.3;
}
.img-container:hover .middle {
opacity: 1;
}
.middleText {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
<div class='img-container'>
<img class='miniProfileImage' src='http://via.placeholder.com/500x500'>
<div class='middle'>
<p class='middleText'>Some Name</p>
</div>
</div>
Thanks
That's because your surrounding <div class='img-container'> has a width that is wider than the image.
If you want the div to have the same size as the image, you can do the following:
.img-container {
position: relative;
display: inline-block;
}
.miniProfileImage {
border-radius: 100%;
border: 3px dashed #28A745;
width: 100%;
max-width: 200px;
height: auto;
transition: .5s ease;
backface-visibility: hidden;
opacity: 1;
display: block;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.img-container {
position: relative;
display: inline-block;
}
.img-container:hover .miniProfileImage {
opacity: 0.3;
}
.img-container:hover .middle {
opacity: 1;
}
.middleText {
background-color: #4CAF50;
color: white;
font-size: 16px;
padding: 16px 32px;
}
<div class='img-container'>
<img class='miniProfileImage' src='http://via.placeholder.com/500x500'>
<div class='middle'>
<p class='middleText'>Some Name</p>
</div>
</div>
please correct the CSS like this
.img-container {
position: relative;
width: 100%;
max-width: 210px;
}
and .middle {white-space:nowrap} you can give .miniProfileImage {max-width:100%} to image
Related
I cannot figure out how to fixate the first part of the text and to make it show from the bottom
on the left is the hover that slides from the bottom and on the right is how it should look like in the beginning
Ive put the code I tried to use inside - please take a look
Thank you!
.container {
padding: 1em 0;
float: left;
width: 50%;
}
.image1 {
display: block;
width: 100%;
height: auto;
transition: all 0.5s ease;
opacity: 1;
backface-visibility: hidden;
}
.middle {
background: rgb(30, 30, 36);
font-weight: 400;
font-size: 16px;
line-height: 22px;
color: rgb(246, 244, 234);
margin: 0px;
}
.middle:hover {
transition: all 0.3s ease-in-out 0s;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.product-box {
overflow: hidden;
}
.product-box:hover img {
transform: scale(1.04);
transition: all 0.8s linear;
}
.product-box:hover {
background: rgba(30, 30, 36, 0.6) !important;
}
.product-box:hover .image1 {
opacity: 0.5;
background: transparent;
}
.product-box:hover .middle {
opacity: 1;
}
.fadeIn-bottom {
top: 80%;
}
<div class="container">
<div class="product-box fadeIn-bottom" style="margin-top: 20px;">
<img src="https://phpmysqlappdiag454.blob.core.windows.net/blob/assets/images/hotelkos/Rectangle 14.png" alt="" data-filename="1.png" style="width: 100%; height: auto; margin-bottom: -40px;" class="image1">
<div class="middle ">
<p style="color: #F6F4EA;">Suites</p>
</div>
<div>
</div>
What you have to do is put the relative, i.e. the product-box in a relative position, then set the absolute position to the "title" to which you want to apply the transition. Once this is done, you need to know how to use transitions and how absolute position works. These two things are important enough to make several cool and simple animations so I recommend you to check them out.
.product-box {
position: relative;
}
.image1 {
width: 100%;
height: 100%;
}
.title {
position: absolute;
bottom: 0;
left: 0;
right: 0;
top: 90%;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0, 0, 0, .5);
color: white;
transition: all .5s;
}
.product-box:hover .title {
top: 0;
}
<div class="container">
<div class="product-box">
<div class="title">
<h4>Suites</h4>
</div>
<img src="https://phpmysqlappdiag454.blob.core.windows.net/blob/assets/images/hotelkos/Rectangle 14.png" alt="" data-filename="1.png" class="image1">
<div>
</div>
I assume this is what you want;
.container {
width: 50%;
}
.image1 {
width: 100%;
aspect-ratio: 1/1;
object-fit: cover;
transition: all 0.5s ease;
opacity: 1;
}
.product-box {
display: flex;
position: relative;
}
.middle {
position: absolute;
width: 100%;
color: #F6F4EA;
background: rgb(30, 30, 36);
font-weight: 400;
font-size: 16px;
line-height: 22px;
margin: 0px;
text-align: center;
padding-top: 10px;
padding-bottom: 10px;
font-family: sans-serif;
display: flex;
bottom: 0;
justify-content: center;
align-items: center;
}
.product-box:hover {
transform: scale(1.04);
transition: all 0.8s linear;
}
.product-box:hover .middle {
opacity: 0.8;
height: 100%;
padding: 0;
}
<div class="container">
<div class="product-box">
<img src="https://phpmysqlappdiag454.blob.core.windows.net/blob/assets/images/hotelkos/Rectangle 14.png" alt="" class="image1">
<div class="middle">Suites</div>
</div>
</div>
For my website I want to use a hover function that shows text once hovering over an imgae with the mouse.
Because I want to implement multiple pictures I used a table whichin each td represents one image.
My problem is that once hovering, the overlay shows but there is no text displayed
I'm a complete beginner in html and css, so if there is anything else I can do different and more efficiently, feel free to let me know.
.container {
position: relative;
width: 50%;
}
.moon {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: relative;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 300px;
width: 300px;
opacity: 0;
transition: .5s ease;
background-color: white;
}
.container:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.text {
color: blue;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.mr {
position: relative;
float: left;
width: 300px;
padding-left: 40px;
}
.mr:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.plant {
position: relative;
width: 300px;
padding-left: 40px;
padding-right: 120px;
float: left;
}
.plant:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.karteone {
position: relative;
width: 300px;
padding-top: 40px;
}
.karteone:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.kartetwo {
position: relative;
float: left;
width: 300px;
padding-top: 39.5px;
padding-left: 40px;
}
.kartetwo:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
<body>
<div class="Arbeitsprobe">
<h2 class="myworksample">My Work Samples.</h2>
<h5>Graphic Illustrator</h5>
<center>
<table>
<tr>
<td>
<div class="container">
<img class="moon" src="images/moon.png" alt="moon">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</td>
<td><img class="mr" src="images/mr.me.png" alt="mr"></td>
<td><img class="plant" src="images/plant planet.png" alt="plant"></td>
</tr>
</table>
</center>
</div>
</body>
You could use tooltip class from css. This will display the tooltip text while hovering.
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: black;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
<div class="tooltip">Hover over me
<span class="tooltiptext">Tooltip text</span>
</div>
If you want the .overlay to appear on .container:hover, then the code sould be: .container:hover .overlay, like so:
.container {
position: relative;
width: 50%;
}
.moon {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: relative;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 300px;
width: 300px;
opacity: 0;
transition: .5s ease;
background-color: white;
}
.container:hover .overlay{
opacity: 0.6;
filter: alpha(opacity=10);
}
.text {
color: blue;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.mr {
position: relative;
float: left;
width: 300px;
padding-left: 40px;
}
.mr:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.plant {
position: relative;
width: 300px;
padding-left: 40px;
padding-right: 120px;
float: left;
}
.plant:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.karteone {
position: relative;
width: 300px;
padding-top: 40px;
}
.karteone:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.kartetwo {
position: relative;
float: left;
width: 300px;
padding-top: 39.5px;
padding-left: 40px;
}
.kartetwo:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
<body>
<div class="Arbeitsprobe">
<h2 class="myworksample">My Work Samples.</h2>
<h5>Graphic Illustrator</h5>
<center>
<table>
<tr>
<td>
<div class="container">
<img class="moon" src="images/moon.png" alt="moon">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</td>
<td><img class="mr" src="images/mr.me.png" alt="mr"></td>
<td><img class="plant" src="images/plant planet.png" alt="plant"></td>
</tr>
</table>
</center>
</div>
</body>
Or apply before and/or after in the CSS, like this:
.container {
position: relative;
width: 50%;
}
.moon {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: relative;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 300px;
width: 300px;
opacity: 0;
transition: .5s ease;
background-color: white;
}
.container:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.text {
color: blue;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.mr {
position: relative;
float: left;
width: 300px;
padding-left: 40px;
}
.mr:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.plant {
position: relative;
width: 300px;
padding-left: 40px;
padding-right: 120px;
float: left;
}
.plant:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.karteone {
position: relative;
width: 300px;
padding-top: 40px;
}
.karteone:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
.kartetwo {
position: relative;
float: left;
width: 300px;
padding-top: 39.5px;
padding-left: 40px;
}
.kartetwo:hover {
opacity: 0.6;
filter: alpha(opacity=10);
}
/* new code from here */
.moon::after {
content: "Hello World";
color: #ffffff;
border: 1px solid #ffffff;
padding: 10px 40px;
display: inline-block;
top: 0;
position: absolute;
margin-top: 55px;
text-align: center;
line-height: 30px;
left: 50px;
text-transform: uppercase;
opacity: 0;
-webkit-transition: opacity 0.35s ease-in-out;
-moz-transition: opacity 0.35s ease-in-out;
-ms-transition: opacity 0.35s ease-in-out;
-o-transition: opacity 0.35s ease-in-out;
transition: opacity 0.35s ease-in-out;
}
.moon:hover::before {
opacity: 1;
transition: opacity 0.35s ease-in-out;
content: "";
background: rgba(0, 0, 0, 0.8);
display: inline-block;
width: 271px;
height: 167px;
top: 0;
position: absolute;
left: 0px;
}
.moon:hover::after {
content: "Hello World";
color: #ffffff;
border: 1px solid #ffffff;
padding: 10px 40px;
display: inline-block;
top: 0;
position: absolute;
margin-top: 55px;
text-align: center;
line-height: 30px;
left: 50px;
text-transform: uppercase;
opacity: 1;
transition: opacity 0.35s ease-in-out;
}
<body>
<div class="Arbeitsprobe">
<h2 class="myworksample">My Work Samples.</h2>
<h5>Graphic Illustrator</h5>
<center>
<table>
<tr>
<td>
<div class="container">
<img class="moon" src="images/moon.png" alt="moon">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</td>
<td><img class="mr" src="images/mr.me.png" alt="mr"></td>
<td><img class="plant" src="images/plant planet.png" alt="plant"></td>
</tr>
</table>
</center>
</div>
</body>
I'm trying to make a card-flip with CSS click-event using an input type that is hidden in the box that every time the user clicks the tile the box will flip and display the content on the back and when the user clicks the back tile it will flip again to the front tile. Here's my code snippet for more info:
.container {
padding: 12rem;
display: flex;
justify-content: center;
}
.tile {
perspective: 100rem;
-moz-perspective: 100rem;
position: relative;
width: 50%;
cursor: pointer;
margin-right: 5rem;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.tile-back, .tile-front {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.tile-back {
transform: rotateY(180deg);
}
.tile-back, .tile-back .card-body {
font-size: 1.5rem;
width: 50%;
text-align: center;
}
.card {
background-color: #58AA3F;
height: 20rem;
transition: all .8s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-radius: 5px;
overflow: hidden;
box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.15);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: all 600ms;
transition: all 600ms;
z-index: 20;
}
.card div {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.card-body {
font-size: 2rem;
color: #fff;
text-align: center;
}
.card-footer {
font-size: 2rem;
}
.card:hover .card {
-webkit-transform: rotateX(20deg);
transform: rotateX(20deg);
box-shadow: 0 20px 20px rgba(50, 50, 50, 0.2);
}
.card input {
display: none;
}
.card :checked + .card {
transform: rotateX(180deg);
-webkit-transform: rotateX(180deg);
}
.card:hover :checked + .card {
transform: rotateX(160deg);
-webkit-transform: rotateX(160deg);
box-shadow: 0 20px 20px rgba(255, 255, 255, 0.2);
}
<div class="tile">
<input type="checkbox"/>
<div class="card tile-front">
<div class="card-body">
<p>Click to display back</p>
</div>
</div>
<div class="card tile-back">
<div class="card-body">
<p>Click to display front</p>
</div>
</div>
</div>
I don't if there's something missing in my code that the input isn't triggering.
I've made a few changes to your code.
For clarity I've left the checkbox visible, but you may hide it.
label[for=test] {
display:block;
-webkit-perspective: 800px;
perspective: 800px;
}
.reversible {
position: relative;
width: 250px;
margin: 50px auto;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-transition: transform 1s ease;
transition: all 1s
}
input[type=checkbox]:checked + label .reversible {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.reversible .card {
position: absolute;
left: 0;
top: 0;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.tile-front {
z-index: 2;
}
.tile-back {
-webkit-transform: rotateY( 180deg);
transform: rotateY( 180deg);
}
.card-body {
font-size: 2rem;
color: #fff;
text-align: center;
}
.card-footer {
font-size: 2rem;
}
.card {
background-color: #58AA3F;
height: 20rem;
transition: all .8s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
border-radius: 5px;
overflow: hidden;
box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.15);
}
<input type="checkbox" id="test"/>
<label for="test">
<div class="reversible">
<div class="card tile-back">
<div class="card-body">
<p>Click to display back</p>
</div>
</div>
<div class="card tile-front">
<div class="card-body">
<p>Click to display front</p>
</div>
</div>
</div>
</label>
I hope it helps
Using this codepen as a basis, I changed it to work with a checkbox
body {
font-family: sans-serif;
}
.scene {
width: 200px;
height: 260px;
border: 1px solid #CCC;
margin: 10px 0;
perspective: 600px;
}
input {
display: none;
}
label {
width: 200px;
height: 260px;
}
.card {
width: 100%;
height: 100%;
transition: transform 1s;
transform-style: preserve-3d;
cursor: pointer;
position: relative;
}
#card:checked + label .card {
transform: rotateY(180deg);
}
.card__face {
position: absolute;
width: 100%;
height: 100%;
line-height: 260px;
color: white;
text-align: center;
font-weight: bold;
font-size: 40px;
backface-visibility: hidden;
}
.card__face--front {
background: red;
}
.card__face--back {
background: blue;
transform: rotateY(180deg);
}
<div class="scene scene--card">
<input id="card" type="checkbox">
<label for="card">
<div class="card">
<div class="card__face card__face--front">front</div>
<div class="card__face card__face--back">back</div>
</div>
</label>
</div>
I need the hover overlay to be the same width as the image. All the images with that overlay effect are different sizes, but use the same classes.
I found answers to a similar problem, but they all include that I need to have the css “absolute” and “relative” properties the other way around. Which I tried, but it made the hover effect stop working.
Any help with this issue would be very much appreciated.
Thanks, Helene
P.S.:Just so you know, I’m fairly new to coding and I’m not an english native speaker…
<!-- HTML mark-up -->
<div class="container">
<a href="#img1">
<img src="resources/img/hgdgdg_TH1.jpg" class="thumbnail" id="linathi_1">
<div class="overlay">
<div class="caption"><i class="ion-ios-pricetag"> €150</i></div>
</div>
</a>
</div>
/* CSS OVERLAY ON HOVER */
.container {
position: relative;
width: 100% /*50%*/;
}
.thumbnail /* image */ {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: rgba(180, 81, 64, 0.85);
overflow: hidden;
width: 100%;
height: 0;
-webkit-transition: .5s ease;
transition: .5s ease;
}
.container:hover .overlay {
bottom: 0;
height: 100%;
}
.caption {
white-space: nowrap;
font-family: 'Assistant', 'Arial', sans-serif;
font-style: normal;
font-size: 130%;
color: #fff;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
width: 100%;
text-align: center;
}
<div class="container">
<a href="#img1">
<img src="https://www.w3schools.com/css/img_fjords.jpg" class="thumbnail" id="linathi_1">
<div class="overlay">
<div class="caption"><i class="ion-ios-pricetag"> €150</i></div>
</div>
</a>
/* CSS OVERLAY ON HOVER */
.container {
position: relative;
width: 100%
}
.thumbnail /* image */ {
display: block;
width: 100%;
height: auto;
overflow:hidden;
}
.overlay {
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
background-color: rgba(180, 81, 64, 0.85);
opacity:0.5;
visibility: hidden;
transition: all .5s ease;
transform: translateY(-100%);
}
.container:hover .overlay,
.container:hover .overlay .caption i {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.container:hover .overlay .caption i {
transition-delay: 300ms;
}
.caption {
font-family: 'Assistant', 'Arial', sans-serif;
font-style: normal;
font-size: 18px;
color: #fff;
position: absolute;
margin:auto;
overflow: hidden;
top: 0;
left: 0;
width: 100%;
height: 100%;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.caption i {
opacity: 0;
visibility: hidden;
display: inline-block;
transform: translateY(-20px);
transition: all .5s ease;
}
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>