image hover area is bigger than the image itself - html

So i have an image i use that is supposed to have a hover function on it. The problem I run into is that the hover area, so where the mouse needs to be to activate the hover function, is way bigger than the image itself. I have linked 2 images below, 1 where the hover is not activated and 1 where it is. On the 2nd image you can clearly see what I mean.
Also below is my HTML and CSS code. I used the following W3 page for this: https://www.w3schools.com/howto/howto_css_image_overlay.asp
Image 1: https://imgur.com/a/jvre00A
Image 2 (you cannot see my mouse, but its all the way over on the right): https://imgur.com/a/OfsQUCB
<div class="containerpic">
<img src="images/duurzaamheid/blauw.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
.containerpic {
position: relative;
width: 180px;
}
.image {
display: block;
width: 180px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 180px;
opacity: 0;
transition: .5s ease;
background-color: green;
}
.container:hover .overlay {
opacity: 0.5;
}
.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;
}

Here, is the example. You may see whether image is static or :hover - the area of image remains same.
If you have added some other effects like img:hover {border: 2px solid #bbb;}, or adding some padding or any other effect - then only you'll get mirage that image-area has changed, while in reality it just remains the same.
img:hover {opacity:0.5}
<div><img src="https://picsum.photos/seed/picsum/100/100" /></div>

I modify your code, let see if this will fix it.
<div class="container">
<img src="https://www.w3schools.com/howto/img_avatar.png" class="image">
<div class="overlay">
<div class="text">
Hello World
</div>
</div>
</div>
.container {
position: relative;
width: 180px;
}
.image {
max-width: 100%;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: .5s ease;
background-color: beige;
z-index: 1;
}
.container:hover .overlay {
opacity: 0.5;
}
.text {
color: black;
font-family: 'Arial';
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
width: 100%;
transform: translate(-50%, -50%);
text-align: center;
z-index: 2;
}

Related

Remove opacity on text [duplicate]

This question already has answers here:
CSS background-image-opacity?
(13 answers)
I do not want to inherit the child opacity from the parent in CSS
(18 answers)
Closed 2 years ago.
I have the following code and have added opacity to the solid overlay colour. The problem is that the text is also using the opacity. How do I change it so that the text does not have the opacity and sits on top?
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
opacity: .5;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.container:hover .overlay {
bottom: 0;
height: 100%;
}
.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">
<img src="https://cdn.searchenginejournal.com/wp-content/uploads/2019/07/the-essential-guide-to-using-images-legally-online-1520x800.png" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
Thanks John
Instead of opacity, use a RGBA color scheme
RGB: #RRGGBBAA, while A is alpha. you can also use rgba(r,g,b,a)
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA99; /* Instead of #008CBA */
overflow: hidden;
width: 100%;
height:0;
transition: .5s ease;
}
.container:hover .overlay {
bottom: 0;
height: 100%;
}
.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">
<img src="https://cdn.searchenginejournal.com/wp-content/uploads/2019/07/the-essential-guide-to-using-images-legally-online-1520x800.png" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
I have had this problem before and i used ::before,
I used it for images but i assume it also works for background colors
CSS i used;
.style::before{
background-image: url(/images/bg_button.png);
background-repeat: no-repeat;
opacity: 0.15;
width: 100%;
height: 100%;
content: "";
background-size: cover;
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
}

Image Hover effect CSS. I want my images to look like this: https://www.medi360.in/NewHome/Our_Specialists.html

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. I want my images to look like these:
https://www.medi360.in/NewHome/Our_Specialists.html
#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: transparent;
overflow: hidden;
width: 100%;
transition: background-color .5s ease;
border-radius:50%;
}
#content .overlay:hover {
bottom: 0;
height: 100%;
opacity: 0.5;
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
transition: background-color .5s ease;
}
#content.text {
color: white;
font-size: 20px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
<div id="content">
<!-- main container-->
<div class="container">
<div class="row sidebar-page">
<!-- Page Content -->
<div class="col-lg-12 page-content">
<!-- Classic Heading -->
<!--first image -->
<div class="col-lg-12 div-gap-padding">
<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"></div>
</div>
</div>
<h3 class="team-prof">
Dr. Pawan Kumar Kesari
</h3>
</div>
</div>
</div>
Apply an id="" or class="" to the img element itself, and set the border-radius of that class or id to 50%, then you can set the hover attribute of the element above it to respond and change color when you hover over that. since you're aligning the image to the element that changes color, the element that changes on hover should have the hover attribute.
For clarification:
#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: transparent;
overflow: hidden;
width: 100%;
transition: background-color .5s ease;
border-radius:50%;
}
#content .overlay:hover {
bottom: 0;
height: 100%;
opacity: 0.5;
position: absolute;
bottom: 100%;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%; border-radius:50%;
transition: background-color .5s ease;
}
#content.text {
color: white;
font-size: 20px;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}

How can I make a left side popup box when hovering element in HTML?

Is there a way to make a text content popup box appear when mouse hovers some HTML element?
I need the overlay to fit its content, because the way it is now is cropping the text, it's getting the height of the HTML element and not the height of its content.
It only slides left, but that's okay with me. I am going to place the html element to the right of the page later on, but I need to be able to set a margin from the starting point of the popup, because it slides just next the HTML element, I'd like some space between.
This is what I have got so far:
.container {
position: absolute;
width: 40%;
}
.overlay {
position: absolute;
bottom: 0;
right: 100%;
background-color: #008CBA;
overflow: hidden;
width: 0;
height: 100%;
transition: 0.5s ease;
}
.overlay:hover {
display: none;
}
.container:hover .overlay {
width: 100%;
right: 100%;
}
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="container">
My Text
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
How can I do that?
See if that's what you're wondering to happen :
#container {
width: 100%;
height: auto;
text-align: center;
margin: 0 auto;
}
.link {
position: relative;
display: inline-block;
}
.link .tip {
visibility: hidden;
width: 0;
height: 100px;
opacity: 0;
background-color: #008CBA;
color: #fff;
text-align: center;
padding: 5px 0;
position: absolute;
z-index: 1;
top: -5px;
right: 105%;
transition: 0.5s ease;
overflow: hidden;
margin-right: 20px;
}
.link:hover .tip {
visibility: visible;
width: 150px;
height: auto;
opacity: 1;
}
<div id="container">
<div class="link">Hover me now !
<span class="tip">
Some few text here<br><br>
Let's try something else<br><br>
And adding more info here too<br><br>
And even a bit more here also
</span>
</div>
</div>

Half shown div slides up on hover

Currently, I copy this code that shows a hidden div on hover
example
but what I want is something like this
goal
What I want is when you hover on title on the 1st box, shown on the 2nd picture, the div containing the title will slide up and occupy the whole space, revealing the other contents below the title.
Can someone recommend me a tutorial similar to this? Thanks in advance :)
/* try this */
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #000000;
overflow: hidden;
width: 100%;
height: 20%;
transition: .5s ease;
}
.container:hover .overlay {
height: 100%;
}
.container .text2{
display:none;
}
.container:hover .text2{
display:block;
padding-top:30px;
}
.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;
}
<h2>Slide in Overlay from the Bottom</h2>
<p>Hover over the image to see the effect.</p>
<div class="container">
<img src="https://www.w3schools.com/howto/img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World
<div class="text2"> content 1</div>
</div>
</div>
</div>
All you need to do is change the height percentage of the overlay box like so..
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #008CBA;
overflow: hidden;
width: 100%;
height: 20%;
transition: .5s ease;
}
.container:hover .overlay {
height: 100%;
}
.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;
}
<!DOCTYPE html>
<h2>Slide in Overlay from the Bottom</h2>
<p>Hover over the image to see the effect.</p>
<div class="container">
<img src="https://www.w3schools.com/howto/img_avatar.png" alt="Avatar" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>

Picture overlay... Only at the area of the real picture and not the background of the picture

I'm a student, and currently busy with creating my own website, but now I've got a question which I can't figure out myself.
My website is about professional cycling and on it I'll have the jerseys of the teams which I want to overlay when going over it with the mouse. I figured this out OK, but now it happens that if I move over it with my mouse, a big square overlays the picture (because it's a square picture with a transparent background) and I want that there is only an overlay over the jersey and not over the "background" of the picture.
I hope you can help me! Need to fix this!
Thank you in advance!
.container {
position: relative;
width: 25%;
height: auto;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background-color: #00b0f0;
opacity: 0.8;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.container:hover .overlay {
height: 100%;
}
.text {
white-space: nowrap;
color: white;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="container">
<a href="AG2R.html">
<img src="https://i.stack.imgur.com/7839q.png" alt="AG2R La Mondiale" title="AG2R La Mondiale" class="image">
</a>
<div class="overlay">
<div class="text">AG2R La Mondiale</div>
</div>
</div>
I found a relevant Stack Overflow thread where the consensus is that this is unachievable with CSS unless you want a pure black image done with filters - which aren't compatible in all browsers and would not have the sliding transition you've implemented.
So I opted to show you how this could look if you created blue overlays yourself in Photoshop as separate PNG images and transitioned with them. I created the PNG by making a layer filled with #00b0f0, set it to 80% opacity and used it as a clipping mask - essentially what your .overlay was trying to do. Here's a demo:
.container {
position: relative;
width: 25%;
height: auto;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
opacity: 0.8;
overflow: hidden;
width: 100%;
height: 0;
transition: .5s ease;
}
.overlay .image {
position: absolute;
bottom: 0;
}
.container:hover .overlay {
height: 100%;
}
.text {
white-space: nowrap;
color: white;
text-shadow: #000 0 1px 1px;
font-size: 20px;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="container">
<a href="AG2R.html">
<img src="https://i.stack.imgur.com/7839q.png" alt="AG2R La Mondiale" title="AG2R La Mondiale" class="image">
</a>
<div class="overlay">
<img src="https://i.stack.imgur.com/DwIGH.png" alt="overlay" class="image" />
<div class="text">AG2R La Mondiale</div>
</div>
</div>