Apply a translucent background color to an image element using CSS

Is there a way to create an overlay div using my HTML markup without adding any additional code?

I want to add a dark overlay with opacity over the image, but I'm limited in what I can use.

 background: rgba(0, 0, 0, 0.5);

Here is the current markup:

<div class="fusion-image-wrapper">
     <a href"#">
        <img src="image-path" >
    </a>
</div> 

Any suggestions on how to achieve this effect?

Appreciate your help!

Answer №1

If you use ::after, there's no need to insert an additional element

.fusion-image-wrapper a {
   position: relative;
   display: block;
}

.fusion-image-wrapper a::after {
   content: "";
   display: block;
   position: absolute;
   top: 0;
   left: 0;
   right: 0;
   bottom: 0;
   background: rgba(0, 0, 0, 0.5);
   z-index: 1;
}

Answer №2

Are you in need of a see-through image against a dark backdrop? :)

.duskenImage{
  display: inline-block;
  background: #000;          /* :) */
}

.duskenImage img {
  vertical-align: middle;
  opacity: 0.5;              /* :) */
}
<a class="duskenImage" href="#">
   <img src="https://loremflickr.com/cache/resized/4698_27827105189_d6ce3f3401_n_300_200_nofilter.jpg" >
</a>

Furthermore, if you include a blend of .jpg and .png images, you can incorporate background: #fff; to the img styles.

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

Learn how to retrieve a meta tag's content value and perform a subtraction operation

I need assistance in retrieving the value of the meta tag content and performing a subtraction operation on it. Could someone lend me a hand with this, please? The meta tag is structured as follows: <meta itemprop="price" content="1699"> I ha ...

Searching for a comprehensive guide to web-related terminology that is widely accepted

Constantly immersing myself in studying the languages I am familiar with and exploring new development concepts and languages is a regular practice for me. When it comes to books, O'Reilly is my go-to choice, but when it comes to online resources, I&a ...

AngularJS Filter from "start to finish" in values

I have been searching everywhere for a solution to this problem, but haven't found one yet. Any help would be greatly appreciated. Angular: var app = angular.module('app', []); app.controller('theController', ['$scope', ...

Safari's flexbox wraps the final column on the top row

When viewed in Safari and some other iOS based browsers, the last column of the first row wraps to the next line. Safari: https://i.sstatic.net/FhYyn.jpg Chrome / Others: https://i.sstatic.net/Vkvr0.jpg Code: .flexthis { display: -webkit-box; d ...

The chat window is tall, stretching to its full height and remains stationary, not moving with the

I seem to be facing a CSS issue with the chat window not taking full height. It doesn't follow along when I scroll to the bottom of the screen. I'm stuck and unsure where to apply min-height: 100%; or if that's even the root cause of the p ...

Django is experiencing difficulties loading CSS on certain template files

Working on my page design using twitter-bootstrap, I've created a base.html file that serves as the global base for all templates to extend. However, I'm facing an issue where upon extending the base.html in all templates, the CSS doesn't d ...

Tips on attaching a click event listener to Nav.Link component in React Bootstrap

return ( <Navbar bg="dark" variant="dark"> <Navbar.Brand href="/">Instagram</Navbar.Brand> <Nav className="mr-auto"> <Nav.Li ...

Please enter the time in minutes and seconds only

Currently, I am attempting to determine a way to create an <input type="time"> field that exclusively shows minutes and seconds. Despite my efforts with time pickers, I have been unable to achieve the desired result. Does anyone have any suggestions ...

IE11 alternative for the CSS property "unset"

I have a div fixed to a specific location on my webpage using the following CSS properties: width: 320px; height: 160px; position: fixed; right: 15px; bottom: 15px; top: unset; z-index: -1; While the div displays correctly in other browsers, in Internet ...

What is the process for displaying data within an Angular 10 component?

As I embark on my journey with Angular 10, my goal is to display the current user in the profile.component.html and the navbar in app.component.html. Below you will find the relevant code snippets: users.ts export interface User { username : string ...

Is there a way to circumvent the eg header along with its contents and HTML code using JavaScript?

I have a script in JavaScript that is designed to replace the content of data-src attribute within each img tag with src. However, I am facing an issue where this script interferes with the functionality of a slider located in the header section. The sli ...

What is the alternative to using <strong> tags in HTML?

Is there a counterpart tag to <strong> in HTML, or is it expected to be included in the upcoming HTML5? ...

Align a text box and button in the center with precision using Bootstrap 5

Here is the code snippet using bootstrap 5: <div style="margin-top: 30%" class="text-center"> <h1>Let's get started...</h1> <input id="form-input" style="display: inline-block;" ...

Troubleshooting: Issues with Integrating Javascript and CSS into

I'm still new to this platform, so please correct me if I make any mistakes. My goal is to create a "task table" that allows users to edit existing tasks and add new ones. Thanks to the base template provided by Ash Blue, I've managed to program ...

"Input numbers into the box provided to calculate the total sum

I have a problem with my code that involves prompting the user to input two numbers and then adding them together. However, when I run the code, it concatenates the numbers as strings rather than performing addition. Here is the code snippet in question: ...

What is the best way in Vue.js to preload images upon the route being loaded without immediately showing them?

Looking to implement a smooth transition effect when switching between different scenarios in a web application. The issue arises when fetching images takes time, resulting in abrupt appearance instead of a gradual transition. Seeking a solution to preload ...

Getting data in a ng-Dialog Modal with AngularJS is a breeze!

Hi there, I'm new to Angular JS and facing an issue with displaying data from my MySQL database in a table as well as in a modal for more detailed information: I've included the HTML file named _detail_modal.html at the bottom of the page. ...

Use the toggle function in pure JavaScript to apply it only to the element that has been clicked

In this HTML code snippet, I am displaying data in a list format with nested subcategories. Each category is displayed as a clickable parent menu item. When clicked, the corresponding subcategories should be toggled to show or hide. <ul id="menu"&g ...

JavaScript error occurs when audio.currentTime is being manipulated.Here is

I am facing an issue with my JavaScript code where I cannot set the currentTime of my audio element. Despite searching for a solution, I have not found this question addressed anywhere else. When I use audio.currentTime = 0;, it results in DOM Exception ...

What could be causing the show() method to malfunction in jQuery?

My attempt at creating a basic slideshow using jQuery involves only 3 images in rotation. To navigate between images, I have utilized the next() method in my code. Here is how it is meant to function: Upon clicking a link (class="next"), a funct ...