Adjust image opacity when hovering and additional styling using CSS

Hello friends at WebDev Experts Forum. I need assistance with replicating a feature found on this website: (specifically the work section). The feature involves an image that darkens upon mouse hover, displays text at the bottom, and includes two circular "buttons" made of Font Awesome icons, all accompanied by some simple animation effects. At the moment, I have only inserted the image within a div element and am unsure how to proceed with implementing the desired functionality. Any guidance or code snippets would be greatly appreciated.

Here is a before and after comparison for reference, in case you prefer not to visit the website directly

Answer №1

If you have a specific requirement in mind, it might be possible to achieve it without the use of javascript. One approach is to utilize the css pseudo-class :hover along with absolute positioning. In this example, I'm showcasing a technique where the background is darkened using a layer above it with a black background that has an opacity of .5 achieved through background: rgba(0,0,0,.5).

.css-hover-effect {
  width: 300px;
  height: 200px;
  overflow: hidden;
  position: relative;
}

.css-hover-effect:hover .overlay {
  opacity: 1;
  pointer-events: all;

}

.bg {
  width: 100%;
  height: 100%;
  background: red;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,.5);
  text-align: center;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.overlay p {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
}

.overlay .fa-links {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}

.overlay .fa-links a {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  border-radius: 50%;
  margin: 5px;
  padding: 5px;
  background: blue;
  text-decoration: none;
  color: #fff;
}
<div class="css-hover-effect">
  <div class="bg"></div>
  <div class="overlay">
    <div class="fa-links">
      <a href="#">A</a>
      <a href="#">B</a>
    </div>
    <p>You're hovering...</p>
  </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

Should I include all components in the app.js file or import them directly into the Vue component?

Now I am faced with two options for injecting my component into my application. The first method is in app.js Vue.component( "notice-master-component", require("./components/site/communication/Notice/MasterComponent.vue") ); In any Vue ...

Categorizations within a drop-down selection

As a beginner in jquery, I am trying to group my dropdown items into "Employee" or "Group" categories using the code below. However, the output is not as expected. Can someone please help me rectify this issue? Thank you! Here's My Code: var selectC ...

How to modify values in a JSON array using JavaScript

Currently, I am facing an issue with displaying dates properly on the x-axis of a graph created using Highcharts. To solve this problem, I need to parse the dates from the JSON response. Despite my attempts to manipulate the JSON date, I have not been able ...

Update a table using PHP and AJAX in real-time

I am working on a page that contains a form table. When a user selects an option from the select dropdown and clicks a button, it triggers an update process in updatephp.php. I want the select options to be dynamically updated and for success/error message ...

Connect the OnClick attribute to a function wrapped by webpack encore

Overview Greetings, (The following introduction provides some context, but feel free to skip it) I am starting a new discussion because it is only loosely related to this particular issue. After exhausting all options and still facing issues with this ...

Objects for requesting and responding

When utilizing express.js, middlewares have the ability to modify both the request object and the response object. This raises the question: what exactly do these request and response objects represent, and what information do they hold? ...

Retrieving JSON data and showcasing it in HTML components

I'm attempting to retrieve JSON responses and showcase them within my predetermined HTML elements. I'm utilizing graphql from datocms. The API explorer displays the following for my model: query MyQuery { allNews { id newsTitle new ...

What steps do I need to take to create a customizable Angular Material NPM module?

Can a custom npm module be created using Angular Material that allows the components to be styled by the consuming app's unique theme? For instance, imagine an npm module with a component containing the following template: <button mat-raised-butt ...

Applying CSS to Dynamic JavaScript Elements: A Guide to Styling Without In-line Code

I'm a beginner in web development and I've been experimenting with applying styles to dynamically generated div elements using JavaScript. So far, I've only been able to manually add inline styling through this function: function applyStyle( ...

Exporting multiple HighCharts visualizations to PowerPoint presentations

Our team is preparing to create an Angular-based web application featuring 15-20 unique charts utilizing HighCharts. One of the key requirements is the ability to export these charts into PowerPoint slides. We are aware that HighCharts offers an option to ...

Navigating through an array with multiple dimensions and varying lengths using d3

I am working with a multidimensional array of integer values to create a dynamic bar graph using d3.js. The challenge lies in the fact that each row can have a variable number of values. My goal is to generate color-coded rectangles for each row based on t ...

Link the global to the Vue component

Is there a way to connect global filters, mixins, and additional features to a specific Vue Instance rather than the Vue object directly? For instance import Vue from 'vue.js' import App from './app' import demo from './mixins/dem ...

Encountering issues with Visual Studio Code following the integration of the MongoDB API Mongoose into my code

As I delve into the world of web development, I have been exploring databases with MongoDB Atlas and mongoose. Interestingly, my debugging process has hit a bump when using the node.js(legacy) debugger in VS code after importing mongoose with const mongoos ...

Utilizing 'this' in jQuery: Image swapping with thumbnails, Twitter Bootstrap framework

Is it possible for jQuery's 'this' to simplify my code? You can view the full code here. Thank you for any help or suggestions. Here is the jQuery code: /* Ref: http://api.jquery.com/hover/ Calling $( selector ).hover( handlerIn, handler ...

How can I hover over multiple cells in a table?

Is there a way to change the color of multiple adjacent cells when hovering over one cell, and can this be done dynamically (so the number of adjacent cells that change color can vary)? Here is the code snippet: I'm using React to create a table wit ...

Achieving responsive design using text font percentage instead of text images can be done by implementing the following code snippet provided below

When working with text in HTML, I encountered an issue where using percentages for width and height was not giving me the desired results. To work around this, I used images of text instead, but each image ended up either stretched or looking too small. H ...

Tips for resolving issues with dropdown menu placement

Here is the current state of my HTML and CSS code: <div class="header"> <div class="container-fluid"> <div class="row"> <div class="col-1"></div> <div class="col-10"></div> <div class="col-1 dropd ...

Utilizing JFlex for efficient brace matching

Currently, I am in the process of developing an IntelliJ plugin. One of the key features that I am working on is a brace matcher. After completing the JetBrains plugin tutorial, I was able to get the brace matcher functioning using this regular expression ...

Components rendered by v-for are failing to display on the production server, however, they are

Struggling to dynamically generate bootstrap tabs (b-tabs) using vue's v-for. Everything functions perfectly on my local server, but once pushed to production, the tabs fail to render. After utilizing the vue chrome debugger to verify that my backend ...

Challenges encountered when attempting to align faces within Three.JS stemming from the use of two distinct

I'm currently facing an issue with my three.js code. My goal is to align two objects by selecting two faces and rotating the second face (and object) to match the normal vector of the first object's selected face. Here is what I have so far: v ...