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>
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>
I have text on top of an image that I'd like to fade in when the image is hovered over, while the image fades out. I've managed to get the transitions to work on the text and the image, but when I hover over the text, the image goes back to full opacity. I'm trying to make it so that when the text is hovered over, the image stays faded out. Here's my code:
.container img {
margin-top: 8px;
vertical-align: middle;
width: 100%;
border: 2px solid white;
border-radius: 20px;
margin-bottom: 5px;
opacity: 1;
transition: .6s ease;
}
.container img:hover {
opacity: .4;
}
.gallery-image {
position: relative;
text-align: center;
font-weight: 700;
line-height: 2rem;
}
.text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: .6s ease;
border: 1px solid;
}
.gallery-image:hover .text {
opacity: 1;
}
<div class="container">
<div class="gallery-image">
<img src="image.jpg" alt="image">
<div class="text">text</div>
</div>
</div>
if you switch the order and have the div before the img, this should achieve what you are looking for:
<div class="container">
<div class="gallery-image">
<div class="text">text</div>
<img src="image.jpg" alt="image">
</div>
</div>
Put the hover state on the the parent container .gallery-image.
.gallery-image:hover img {
opacity: .4;
}
.gallery-image:hover .text {
opacity: 1;
}
.container img {
margin-top: 8px;
vertical-align: middle;
width: 100%;
border: 2px solid white;
border-radius: 20px;
margin-bottom: 5px;
opacity: 1;
transition: .6s ease;
}
.gallery-image:hover img {
opacity: .4;
}
.gallery-image:hover .text {
opacity: 1;
}
.gallery-image {
position: relative;
text-align: center;
font-weight: 700;
line-height: 2rem;
}
.text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity: 0;
transition: .6s ease;
border: 1px solid;
}
<div class="container">
<div class="gallery-image">
<img src="image.jpg" alt="image">
<div class="text">text</div>
</div>
</div>
I want my image hovers to look like this,
but For some reason, my CSS styling is not working. You may notice the #content in each of the CSS styling options. That is because I only wanted these styles to apply to a certain section of my website. I looked online and used the W3Schools resource, yet for some reason, it still doesn’t work. My images do not have the hover effect.
#content.container {
position: relative;
width: 50%;
}
#content img {
width: 100%;
height: auto;
border-radius: 50%;
}
#content .column {
float: left;
width: 33.33%;
padding: 5px;
}
#content .row::after {
content: "";
clear: both;
display: table;
}
#content .overlay {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
border-radius: 50%;
}
#content .img:hover .overlay {
bottom: 0;
height: 100%;
opacity: 0.5;
}
#content.text {
color: white;
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;
}
<div class="container">
<div class="column">
<div class="team">
<div class="img">
<img src="/static/img/team/team-1.jpg" alt="" style="width: 200px;">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<h3 class="team-prof">
Dr. Pawan Kumar Kesari
</h3>
</div>
</div>
</div>
It seems you haven't followed THIS guide very well.
You also have not identified what #content is.
You need to revise how you target IDs, Classes and Elements in CSS.
Here is your code remodified to follow the guide, plus I added in #content for you.
#content .img {
position: relative;
width: 50%;
}
#content img {
display: block;
width: 200px;
height: auto;
border-radius: 50%;
}
#content .overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 200px;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
border-radius: 50%;
}
#content .img:hover .overlay {
opacity: 1;
}
#content .text {
color: white;
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;
}
<div id="content">
<div class="container">
<div class="column">
<div class="team">
<div class="img">
<img src="https://www.w3schools.com/howto/img_avatar.png" alt="">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<h3 class="team-prof">
Dr. Pawan Kumar Kesari
</h3>
</div>
</div>
</div>
</div>
There were flaws in your code. There was no shared container. There were no spaces in the css rules between the identifier and the classes. #content .overlay had a height: 0 - this makes the object invisible. My answer isn't perfect, but I've tidied up the code a bit.
.main {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh;
}
.main_content {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
width: 1000px;
}
.main_content_box {
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
}
.main_content_box_image {
position: relative;
}
.main_content_box:hover > .main_content_box_image p {
display: flex;
}
.main_content_box:hover > .main_content_box_image img {
filter: brightness(25%);
}
.main_content_box:hover a {
color: #337ab7;
}
.main_content_box_image img {
width: 250px;
height: 250px;
border-radius: 125px; /* or 50%*/
transition: .5s;
}
.main_content_box_image p {
display: none;
position: absolute;
top: 40%;
left: 20%;
right: 0;
font-size: 14px;
color: #fff;
}
.main_content_box a {
color: #333;
font-size: 16px;
font-weight: bold;
text-decoration: none;
margin: 20px 0 0 0;
}
<div class="main">
<div class="main_content">
<div class="main_content_box">
<div class="main_content_box_image">
<img src="https://icdn.lenta.ru/images/2019/11/01/13/20191101130724350/pwa_vertical_1024_f1555b2890fcb39f7ecc85cf65e73fc5.png" alt="">
<p>MBBS, General Physician</p>
</div>
Dr. Pawan Kumar Kesari
</div>
<div class="main_content_box">
<div class="main_content_box_image">
<img src="https://icdn.lenta.ru/images/2019/11/01/13/20191101130724350/pwa_vertical_1024_f1555b2890fcb39f7ecc85cf65e73fc5.png" alt="">
<p>MBBS MD(Medicine) General Physician</p>
</div>
Dr. Nitin Kumar Srivastava
</div>
<div class="main_content_box">
<div class="main_content_box_image">
<img src="https://icdn.lenta.ru/images/2019/11/01/13/20191101130724350/pwa_vertical_1024_f1555b2890fcb39f7ecc85cf65e73fc5.png" alt="">
<p>MBBS General Consultant and Diabetician</p>
</div>
Dr. (Mrs) Halima
</div>
</div>
</div>
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
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;
}