I have an image with some overlay text. Whenever I hover my mouse over my image, the content displayed once hovered is moved to the left of the original image. The hovered content is shifted 69 pixels to the left. I want the hovered content to be directly hovered over the image. How can I fix this?
HTML
<div class="row">
<div class="container col-lg-3">
<img src="Images/Coding.jpg" alt="" class="image">
<div class="description">
<h6 class="titles">
Coding
</h6>
<br>
<i class="far fa-keyboard fa-2x"></i>
<br>
<br>
<p>
Projects | Learning | Design
</p>
</div>
<div class="overlay">
<div class="text">
<h5>
Take a peak at my offers, current projects, and qualifications
</h5>
<br>
<a class="btn btn-outline-light btn-sm" href="coder.html" role="button">
Explore more
</a>
</div>
</div>
</div>
</div>
CSS
.container {
position: relative;
width: 250px;
height: 250px;
}
.container:hover .overlay {
opacity: 1;
}
.image {
display: inline-block;
width: 250px;
height: 250px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 250px;
width: 250px;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.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;
}
Because container class tacking a padding so please add padding:0px;
.container {
position: relative;
width: 250px;
height: 250px;
padding:0px;
}
Related
I have a navigation on the right side of the page, and I made an animation where when you hover on a button it enlarges and shows the page name.
// This is the JavaScript code where I make the Buttons Wider:
document.querySelectorAll(".nav-button").forEach(elem => elem.addEventListener("mouseover",
() => {
elem.querySelector(".nav-hover").style.width = "300%";
}));
document.querySelectorAll(".nav-button").forEach(elem => elem.addEventListener("mouseout",
() => {
elem.querySelector(".nav-hover").style.width = "";
}));
.navigation {
z-index: 10;
position: absolute;
right: 0px;
}
.navigation .buttons {
position: absolute;
top: 50%;
transform: translate(-50%, -50%) !important;
}
.button-el {
height: 65px;
margin-bottom: 30px;
}
.button-el i {
color: var(--text-color);
font-size: 28px;
position: relative;
float: right;
margin-top: 15px;
margin-right: 15px;
}
.nav-hover {
z-index: -1;
transition: width .5s ease-out, opacity 0s, all 1s;
position: relative;
width: 65px;
height: 65px;
border-radius: 500px;
float: right;
background-color: var(--dark1);
border: var(--accent1) 3px solid;
}
<div class="buttons">
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-house"></i>
</div>
</div>
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-user-large"></i>
</div>
</div>
<div class="nav-button button-el home">
<div class="active"></div>
<div class="nav-hover">
<i class="fa-solid fa-house"></i>
</div>
</div>
</div>
I think that the cause might be in the Javascript since the .buttons DIV moves when you activate very fast multiple addEventListener (mouseover and mouseout).
The problem is in the .navigation .buttons selector:
.navigation .buttons {
position: absolute;
top: 50%;
transform: translate(-50%, -50%) !important;
}
It seems like what did change it was the x in translate(x, -50%). Now it looks like this:
.navigation .buttons {
position: absolute;
top: 50%;
right: 67%;
transform: translate(0, -50%) !important;
}
I'm trying to implement a flipping card, and place two tags at the back of the card. What happens is that first a tag inside div.sm is not clickable and second is working fine. Below are JSX and CSS/SCSS.
It also starts happening when I add transform: translate(-50%,-50%) to sm class. Thank you for the help
.flip-card {
background-color: transparent;
width: 300px;
height: 300px;
perspective: 1000px;
}
.col-1 {
margin-left: -30px;
width: 200px;
height: 300px;
}
.flip-card-inner {
position: relative;
width: 100%;
height: 100%;
text-align: center;
transition: transform 0.7s;
transform-style: preserve-3d;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}
.flip-card-front,
.flip-card-back {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
overflow: hidden;
}
.flip-card-back {
background-color: #2f2f2f;
color: white;
transform: rotateY(180deg);
}
.flip-card-back-content {
text-align: center;
width: 100%;
position: absolute;
}
.sm {
background-color: $off-white;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
<div className="flip-card col-1">
<div className="flip-card-inner">
<div className="flip-card-front">
<img src="#"/>
</div>
<div className="flip-card-back">
<div className="flip-card-back-content">
<h5>Text</h5>
<span>Some text</span>
<div className="sm">
<a
href="#"
>
<FaGlobeAmericas />
</a>
<a
href="#"
>
<FaGlobeAmericas />
</a>
</div>
</div>
</div>
</div>
</div>
I think the problem is that you have made some tags instead of text in the a tags.
FaGlobeAmericas in not a valid html tag.
Test if this html code works.
<div className="flip-card col-1">
<div className="flip-card-inner">
<div className="flip-card-front">
<img src="#"/>
</div>
<div className="flip-card-back">
<div className="flip-card-back-content">
<h5>Text</h5>
<span>Some text</span>
<div className="sm">
<a
href="#"
>
FaGlobeAmericas
</a>
<br>
<a
href="#"
>
FaGlobeAmericas
</a>
</div>
</div>
</div>
</div>
</div>
I've added an image overlay in HTML on my website to link to social media. It looks good on all platforms except for a small issue on mobile - when clicking on the image the overlay turns to a square very briefly before it reverts back to a circle. Example attached... Does anybody know how to fix this?
.circle {
position: relative;
width: 50%;
margin: auto;
border-radius: 50%;
height: 200px;
width: 200px;
overflow: hidden;
display: flex;
justify-content: center;
}
.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;
}
.circle:hover .overlay {
opacity: 1;
}
.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 style="position:relative;">
<div style="color:#ddd;background-color:#282E34;text-align:center;padding:50px 80px;text-align: justify;">
<h2 style="color:#777;text-align:center;font-weight:bold">Meet The Founders</h2>
<br>
<h3 style="color:#777;text-align:center;">Andy Lee, Director of International Operations</h3>
<br>
<div class="circle"><img src="https://s.abcnews.com/images/Sports/WireAP_ace5eb7b9eca42d899e39c8756720d02_16x9_992.jpg" height="200" width="200" class="image" alt="Andy Lee, Director of International Operations" />
<div class="overlay">
<div class="text"> <img src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/linkedin_circle-512.png" height="48" width="48" /></div>
</div>
</div>
<br>
<p style="text-align:center;">Andy spent over a decade working in the UK IT sector before returning to his native Kuala Lumpur. He's worked as a trader and software developer for the Royal Bank of Scotland and Sky Betting and Gaming.</p>
<br>
</div>
I'm working on my portfolio site now. My projects are listed as clickable images, arranged into two columns. I want it that when a user hovers over an image, a solid block of color covers it with the project title in the center. Basically like this: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_image_overlay_fade.
I had it working perfectly when I used row/column css classes, but since I've found that to not be very responsive (on mobile, the first column gets stacked on top of the other, which makes sense but that's not the order I want), I aligned the images with float and padding instead. Now, the hover effect/link stretches across the entire page, instead of being contained in the image area.
Here's my code for reference:
CSS
.container {
position: relative;
}
.image {
display: block;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
height: 100%;
width: 100%;
transition: .5s ease;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 30px;
font-family: "Lato-Bold";
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
#media screen and (min-width: 1025px) {
.image {
float: left;
width: 45%;
padding-left: 40px;
padding-right: 15px;
padding-bottom: 30px;
}
}
HTML
<div class = "container">
<img src="image name" class = "image">
<div class="overlay" style = "background-color: #color;">
<div class="text">project title</div>
</div>
</div>
How can I fix this? I've tried adding display: block to the .overlay class. I've tried making the .overlay class the same size as the image. I've also tried wrapping the link around the container class instead of the other way around like it is now. Nothing happens at all. I've also tried adjusting the container size, but that shrunk the images and stacked them into 1 column :(
Read about Responsive Images and Flexbox
Try the following code.
Note: I changed the HTML structure slightly.
.container {
display: flex;
justify-content: center;
flex-wrap: wrap;
}
.thumb {
position: relative;
width: 50%;
}
.thumb img {
width: 100%;
}
.thumb:hover .overlay {
opacity: 1;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
height: 100%;
width: 100%;
transition: .5s ease;
color: #000;
background: #fff;
}
.overlay .text {
position: absolute;
top: 50%;
transform: translate(-50%);
left: 50%;
text-align: center;
}
<div class="container">
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
<a href="#" class="thumb"><img src="https://loremflickr.com/320/240/dog" alt="" />
<div class="overlay">
<div class="text">project title</div>
</div>
</a>
</div>
Is there any way of making this overlay more responsive? As in, making the overlay not cut off words, or go outside the image when resolution changes?
To further clarify: I am having three images next to each other in a row, per the W3CSS framework I am using, with three images under that, etc. Each image has an overlay with text links that direct to other pages, as shown in the example below. My only issue is responsiveness. As I want the images, and the overlays, to be responsive to screen size changes and 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">
Google Sample1<br>
GoogleSample2<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, that your image is the same width as parent, you better use not only width = 100% property, but min-width = 100% and max-width = 100% too. If you want to keep the dimensions of image, you also should point height = auto, but in your case it should be height = auto !important. And for breaking long words in overlay, i have added the following rules:
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-all;
word-break: break-word;
hyphens: auto;
Here is the 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">
Google Sample1<br>
GoogleSample2<br>
</div>
</div>
</div>
<div class="w3-container w3-white" style="height:50px;width:400px">
<h3>Example 1</h3>
</div>
</div>
Background-size:cover is your friend when it comes to responsive images. With the image being the background, cover will position it so it fits the width/height automatically and will resize in the other direction that it doesn't fit so that it keeps the ratio. That way the image looks like it stays the same size the whole time, but it's responsive and doesn't get distorted.
.container {
position: relative;
width: 0%;
}
.w3-third{
background-image:url('http://www.fillmurray.com/200/300');
background-size:cover;
background-position:center center;
height:300px;
width:33.333%;
float:left;
display:block;
position:relative;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
transition: .5s ease;
background-color: #008CBA;
}
.w3-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="overlay">
<div class="text">
Google Sample1<br>
Google Sample2<br>
</div>
</div>
</div>
<div class="w3-third w3-container w3-margin-bottom">
<div class="overlay">
<div class="text">
Google Sample1<br>
Google Sample2<br>
</div>
</div>
</div>
<div class="w3-third w3-container w3-margin-bottom">
<div class="overlay">
<div class="text">
Google Sample1<br>
Google Sample2<br>
</div>
</div>
</div>
</div>