Opacity changes intermittently while hovering over text link

It seems like I'm facing a common issue, but none of the solutions I've found from previous Stack Overflow posts are fixing it. On my website, I have multiple images that should display text (including a link) over them with reduced opacity when hovered over. However, when I hover over the image, the hover effect flickers and loses focus. I've tried enclosing the image and text within a div as suggested in this post: Hover-Effect disappears, when hovering over Text. Unfortunately, that solution is not working for my situation.

.hover_img:hover img {
    opacity: .2;
}

.portfolio_img:hover + .center_text {
    display: block;
}

.center_text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    font-weight: bold;
}
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="hover_img">
<img class="portfolio_img" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Image">
<div class="center_text">Click here for info <a href="https://stackoverflow.com" target="_blank">Stackoverflow</a></div>
            </div>
    </div>
    </div>
</div>

Answer №1

When you encounter the issue of confusion with .portfolio_img:hover while hovering over text, a simple solution is to update it to .hover_img:hover

.hover_img:hover img {
    opacity: .2;
}

.hover_img:hover .center_text {
    display: block;
}

.center_text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    font-weight: bold;
}
<div class="container">
<div class="row">
<div class="col-md-4>
<div class="hover_img">
<img class="portfolio_img" src="https://www.w3schools.com/w3images/fjords.jpg" alt="Image">
<div class="center_text">Click here for info <a href="https://stackoverflow.com" target="_blank">Stackoverflow</a></div>
            </div>
    </div>
    </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Create a dynamic table component that automatically displays the values of each property in the current object data iteration using the ngFor directive

Let's get straight to the point, I am working on a table component that takes in an Object containing all the necessary information for a dynamic table, including header details. My goal is to make it possible for each row of data to display its value ...

Script for converting Fixed Positioned Elements to Static

I am frequently finding that elements on web pages are causing disruptions due to their fixed positioning. I am exploring ways to disable the position: fixed CSS rules on any website I visit. To address this issue, I have developed a userscript specifical ...

Utilize Jquery to dynamically update form input in real time based on checkbox selections

I am working on a form that requires real-time calculation of GST (Goods and Services Tax) directly within the form (GST = Price/11) This functionality has been implemented with the following script. Additionally, the calculation needs to be adjust ...

After adding elements with jQuery, make sure to select them correctly

When I click a button on my page, it appends an element with the class .select2-selection__rendered. I need to get the text of this appended element for use in an AJAX call. However, when I tried to alert its text, I found that it was blank. The appending ...

Seeking help on modfiying div content with AJAX - any tips for showing navigation using hash or anchor?

Looking to create a dynamic page that updates content within a div asynchronously while also providing users with direct access to specific content within the div by using anchors (e.g. www.website.co.uk/#page1). I've successfully implemented the upd ...

What is the optimal nesting sequence of <a/> and <h1/> in HTML?

When nesting <a> and <h1> elements in HTML, is there a preferred order? For example: <a href="www.example.com"><h1>Example!</h1></a> or <h1><a href="www.example.com">Example!</a></h1> ...

Using Javascript to dynamically add and remove elements on click

Whenever I click on a link, I am able to generate input, label, and text. However, I want to be able to delete these elements with the next click event on the same link: I've tried updating my code like this: var addAnswer = (function() { var la ...

Issue with PHP causing Jquery alert to trigger twice rather than once

I am currently working with jQuery and PHP. I have a button labeled "Edit" but whenever I click on it, the alert message pops up twice instead of just once. Below is my HTML code within the PHP tags: <?php $PostComment2='<div class="button1 ...

What is the best way to modify the background of my li element when it is clicked on?

I stumbled upon this article: Modifying Li Element Colors in HTML <ul> Using onclick Event It seems to address what I need, but I'm a little unsure of how to implement something similar in a rails app that also utilizes react/redux. Most of the ...

Place the div directly beside the input field on the right side

I am attempting to align a div directly beside the text being entered in a text input field. It seems logical to me that this could be achieved by measuring the length of the input value and positioning the div accordingly. However, the issue I am facing i ...

Issue with Modal Display in Bootstrap 5

I am experimenting with opening a modal when an image is clicked using the following code snippet: <!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target=&quo ...

Replacing the absence of value with an empty string within a textfield using Lit-element

In my current project, I am utilizing Lit-element and mwc-element. Within this setup, I have two string variables and an object variable that holds the string values. My goal is to populate a text-field with these object values. So far, I have managed to a ...

The image is failing to function as a hyperlink

My <img> element is wrapped in an anchor tag, but it's not behaving like a link. Strangely, the <p> tag is acting as a link instead. How can I make the image function as a link without needing the <p> tag? Currently, there is no cur ...

What could be causing my inability to accurately guess people's ages?

My latest project involves developing a game where players have to guess names from images. Each game consists of 10 rounds, followed by a bonus round where participants must wager their points on guessing the age of the person in the image within a 2-year ...

When using the get function, the HTML text remains unchanged

In my game, I am encountering an issue where the score does not update within my get function every time the game is played. Instead, I keep receiving null property errors. Any assistance on resolving this would be highly appreciated. I attempted to inclu ...

Fixing blurry text on canvas caused by Arbor.js mouse event issues

Currently, I am utilizing arborjs in my project. The text within the canvas is created using fillText in html5. While everything functions correctly on a Retina display MacBook, the text appears blurry. To address this, I applied the following solution: v ...

Guide on executing a function upon clicking the ok button in an alert box in PHP and MySQL

function notify(message) { alert(message); handleAlert(); } function handleAlert() { alert('Alert has been triggered.'); } //I am looking for a way to trigger an update or insert action when the user clicks 'OK' on the alert ...

Sas: The outcome matches the viewer results exactly

I am reaching out because I am experiencing an issue with my results viewer in Sas 9.4. When the results load, they appear similar to the output format. Instead of displaying a table with cells, it appears as a table drawn with -+|. The layout options do ...

Enhancing Image Quality in Microsoft Edge

I'm trying to figure out how to make an image scale with bicubic in MS Edge. Is there a CSS solution or something similar that can change this behavior? Check out this page: On the right side of the page, there are two images with textured backgroun ...

I'm having trouble passing my jQuery variable to a PHP file using the POST method

I am trying to send a variable to the PHP file select.php using AJAX in order to populate a table based on a specific date that is taken from an input field. In my AJAX script, I have set up a function to get the value of the date when a button is clicked ...