What is the process for adding a custom color as a see-through overlay on an image?

https://i.sstatic.net/eZBnd.png

I'm struggling to implement the hover effect shown above. I specifically need assistance with creating a gold transparent filter using a 100% linear gradient when hovering over the image, but my attempts have been unsuccessful so far. I've also experimented with the filter property, but I can't figure out how to use a custom color instead of the presets provided.

Here's the HTML code:

    <figure>
    <a href=#><img src="assets/instagram-1.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
    </figure>
    <figure>
    <a href=#><img src="assets/instagram-2.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
    </figure>
    <figure>
    <a href=#><img src="assets/instagram-3.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
    </figure>
    <figure>
    <a href=#><img src="assets/instagram-4.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
    </figure>
    <figure>
    <a href=#><img src="assets/instagram-5.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
    </figure>
    <figure>
    <a href=#><img src="assets/instagram-6.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
    </figure>
  </div>

And here's the corresponding CSS code:

.footer-col-4 {
  width: 21.5rem;
  padding-left: 1.75rem;
}

.footer-col-4-images {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}

.footer-col-4-images figure:nth-child(-n+3) {
  margin-bottom: .75rem;
}

.footer-col-4-images figure {
  position: relative;
}

.footer-col-4-images i {
  color: #e4e4e4;
  position: absolute;
  top: 30%;
  right: 0;
  left: 40%;
  bottom: 0;
  font-size: 1.4rem;
  visibility: hidden;
}

.footer-col-4-images figure:hover {
  background: linear-gradient(90deg, rgba(238,176,19,0.5) 100%, rgba(238,176,19,0.5) 100%);
}

.footer-col-4-images figure:hover i{
  visibility: visible;
}

Answer №1

It appears that you are adding a background color to the figure, which may be hidden by the image itself. A better approach would be to apply the background color to the overlay element i, making it 100% wide and tall. Once this is done, centering the content of the overlay becomes a simple task.

.wrap {
  display: inline-block;
  position: relative;
}

i.fa {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2em;
  color: white;
  background: linear-gradient(90deg, rgba(238, 176, 19, 0.5) 100%, rgba(238, 176, 19, 0.5) 100%);
  visibility: hidden;
}

figure:hover i {
  visibility: visible;
}
<figure class="wrap">
  <img src="http://www.placebacon.net/300/210?image=1" alt="">
  <i class="fa fa-search"></i>
</figure>

View Codepen.io Demo

Answer №2

If my understanding is accurate, you are looking to set a custom color for the gradient effect when hovering over an element.

Have you considered adding it as an inline style?

<figure style="background-color: linear-gradient(..)">
    <a href=#><img src="assets/instagram-1.jpeg" alt=""></a>
    <i class="fas fa-search"></i>
</figure>

Alternatively, you could incorporate the background-color as a class and apply distinctive styles to each figure.

.footer-col-4-images figure.red:hover {
  background: linear-gradient(90deg, rgba(...) 100%, rgba(...) 100%);
}

.footer-col-4-images figure.blue:hover {
  background: linear-gradient(90deg, rgba(...) 100%, rgba(...) 100%);
}

<figure class="red">

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

Tips for choosing the element next to it with XPath?

Looking at this code snippet, there appears to be a Dropdown list element. Could you provide guidance on writing the XPath for this particular element? <div class="dropdown "> <button class="btn btn-default dropdown-toggle btn-block" type=" ...

The PHP tag is being terminated by the code within the query $db->

Apologies for my lack of recent experience in php. I am revisiting some old code to troubleshoot a peculiar issue that has arisen. Within the realm of wordpress, I find myself editing php code and noticing an unexpected closure of the php tag below: <? ...

Eliminating the bottom border of all buttons, except for the last three buttons in the list, solely using pure JavaScript, unless alternative methods are available

I have 3 sets of buttons, with each set containing 9 buttons stacked in 3 columns inside an ordered list (ol) within list items (li). I have removed the bottom border of the buttons to avoid double borders since they are stacked on top of each other withou ...

What is the most efficient way to import all scripts, stylesheets, and markup using just one JavaScript file?

In the realm of a fixed small snippet of code that cannot be altered after deployment (in an RIA), all elements are required to be loaded through a bootstrapper.js file: <div id="someDivID"></div> <script type="text/javascript" src="bootstr ...

What is the best way to combine two pieces of information from a constantly changing table?

Could really use some help with jQuery! I'm trying to calculate the cumulative value from columns A and B, then add those values together. Check out this image for the expected output. <script src="http://code.jquery.com/jquery-1.11.2.min.js"> ...

Arrange divs next to each other using CSS

I am currently working with a basic layout on my webpage <div id="content-wrap"> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div ...

Ways to automatically change a URL into a clickable link upon pasting

When attempting to paste a URL into the text box such as https://stackoverflow.com/, it does not automatically convert to a hyperlink. I previously tried using regular expressions in this related question. The function I implemented worked correctly, howe ...

Having trouble with jQuery's .animate() on a basic horizontal slider?

I attempted to customize this jQuery slider solution from Stack Overflow: (using the first solution - http://jsfiddle.net/sg3s/rs2QK/). Check out my modified version on jsFiddle here: http://jsfiddle.net/markrummel/KSHSX/. The slide-in effect for the DI ...

Footer that sticks to the bottom of the page across various pages

Having trouble printing a 2-page document on Chrome. The first page has fixed content while the second page has dynamic content in an extended table. The problem I'm facing is keeping the footer at the bottom of the second page. The CSS code below wo ...

Achieving a tidy layout with child divs inside a parent div

I'm struggling to figure out how to arrange objects with margins inside a parent div. Initially, I thought using float would do the trick, but I quickly realized it wasn't the solution. This results in an unsightly amount of space. The divs that ...

A simple method to make an element visible across all breakpoints except for 'xs' in Twitter Bootstrap 3

As a beginner in bootstrap, I've been exploring the documentation and came across an interesting feature. It seems that you can assign a class to a default invisible object to make it visible for specific breakpoints such as visible-xs, visible-md, wh ...

Interactive dropdown menus using HTML and jQuery

My goal is to dynamically update a group of select boxes when another select box is changed. The challenge I'm facing is getting some of the select boxes to have the same options while allowing for the user to add more selects as needed. There will b ...

flexible navigation bar with Bootstrap

I'm currently using Yamm with Bootstrap, but I'm encountering an issue where I need to make it flexible so that each list item will have the same spacing as the others. Additionally, I want to be able to add new list items in the future without d ...

unable to get highcharts to redraw and reflow properly

I am currently working on creating a dynamic page that can display between 1-4 graphs. These graphs need to be able to resize when added or removed from the page. However, I have encountered a major issue with resizing the graphs after resizing the contain ...

Struggling to click on a link while viewing the site on your mobile device?

Recently dove into the world of implementing mobile responsive design for a website I've been working on. While conducting some testing, I observed that the main tabs which direct users to different sections of the site, normally easy to click on desk ...

Struggling to resize tables in React Material-UI

Here is my SandBox link for reference: https://codesandbox.io/embed/material-demo-j6pz9?fontsize=14&hidenavigation=1&theme=dark I am attempting to organize content within a card using an inline grid display to have them appear side by side. I unde ...

Angular 4 navbar seamlessly integrated with Bootstrap 4

I have recently developed an Angular 4 application and I am looking to integrate Bootstrap 4 into it. After installing Bootstrap 4.0.0-beta6 via npm, I wanted to use the starter template which should resemble this design. https://i.sstatic.net/ANaBz.png ...

The slide effect in jQuery's show() function isn't being displayed as expected

How can I implement a slide effect to hide and show an article element based on different navigation clicks? When loading the page, clicking on Home smoothly hides the article with no issues. However, when clicking on the About Us link, the article is imme ...

Add some flair to the html and body elements for a designated React Route

Ensuring that an iframe is rendered at 100% for both width and height can be a challenge. The method outlined in this Stack Overflow post offers a potential solution. body, html {width: 100%; height: 100%; margin: 0; padding: 0} .row-container {display: ...

What can I do to prevent a panel from being pushed beneath two other panels when the window size is reduced?

These are my three panels: ___ _________ ___ | | | | | | | | | | | | | | | | | | | | | | | | |___| |_________| |___| When I resize the window slightly, the layout changes: ___ ...