Apply a dark overlay effect to a div when hovering over it

Having multiple div elements with content, I am attempting to add a dark overlay when hovered over.

Here is my HTML code:

<div class="main-slider">
    <div class="owl-item">
        <li class="dark-overlay">
            //content
        </li>
    </div>
    <div class="owl-item">
        <li class="dark-overlay">
            //content
        </li>
    </div>
    <div class="owl-item">
        <li class="dark-overlay">
            //content
        </li>
    </div>
</ul>

My attempt using CSS is as follows:

.dark-overlay{
  background:rgba(0,0,0,.75);
  text-align:center;
  padding:45px 0 66px 0;
  opacity:0;
  -webkit-transition: opacity .25s ease;
}

.main-slider li:hover {
  opacity:1;
}

However, the implementation is not functioning as expected.

Answer №1

Replacing li with div in the code snippet provided. The dark overlay effect will only be visible on hover, as it adds a semi-transparent black background to the content.

If you have specific expectations or requirements for how you want this to look, please provide more details so we can assist you better.

.dark-overlay {
  background: rgba(0, 0, 0, .75);
  text-align: center;
  padding: 45px 0 66px 0;
  opacity: 0;
  -webkit-transition: opacity .25s ease;
}

.main-slider div.dark-overlay:hover {
  opacity: 1;
}
<div class="main-slider">
  <div class="owl-item">
    <div class="dark-overlay">
      content
    </div>
  </div>
  <div class="owl-item">
    <div class="dark-overlay">
      content
    </div>
  </div>
  <div class="owl-item">
    <div class="dark-overlay">
      content
    </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

Ensure the table row remains on one page when printing or viewing the print preview

I'm currently dealing with an html report that contains a table, which can be seen here http://jsfiddle.net/fhwoo3rg/2/embedded/result/ The issue arises when trying to print the report, as it breaks in the middle of a table row like this: https://i ...

Creating a responsive HTML, CSS, and JavaScript popup: A step-by-step guide

I'm facing a challenge in making my HTML, CSS, and JavaScript popup responsive. Despite looking into various resources, I haven't been able to find a solution that fits my code. However, I am confident that it is achievable to make it responsive! ...

Having trouble with inserting data into MySQL database using PHP?

I am currently facing an issue while attempting to insert data into a MySQL database. Although no errors are appearing during the process, when I try to browse the data, it doesn't seem to be getting inserted into the database. Below is my code, could ...

I'm looking for a tool that can automatically create HTML and CSS code to place a shape over a jpeg image

I have a photo of a living room with a TV. I would like to cover up the TV with a basic 2D shape (such as a white square) that will be displayed on the image using HTML/CSS. If the TV is located at coordinates ([200,300],[150,400]), the square shape shoul ...

A guide to seamlessly integrating Vue.js directives within custom Django template tags

One of the challenges I encountered in Django was creating a custom template tag named text_field @register.inclusion_tag('form_field_tags/text_field.html') def text_field(field, prefix=None, field_type=None, attr=None, **kwargs): return { ...

What is causing the border-bottom in these inline divs to not display when using a fractional height? (Specifically in Chrome)

Here is a jsfiddle I'd like to share with you: https://jsfiddle.net/ionescho/4d07k799/4/ The HTML code: <div class='container'> <div class="row"></div><div class="row"></div><div class="row"></div> ...

Comparison between Mobile Phone's innerWidth and innerHeight Versus Resolution

My test phone, the Galaxy S3 Mini, has a resolution of 800x480 according to its specs. Strangely, when I run the following code in my HTML game: window.innerWidth window.innerHeight The width appears as 533 and the height as 295. I recently discovered ...

Is there a discrepancy in absolute positioning offset between IE7 and Firefox?

I'm currently reorganizing a fellow developer's code, and it seems that the CSS work was done poorly. Within the main "wrapper" div on the page, there are logos and navigation images. The images are positioned using "position: absolute" and the ...

Is there a way to have an HTML scrollbar automatically start at the bottom?

I'm having trouble ensuring that my chatbox's scrollbar automatically starts at the bottom so that new messages are visible without needing to scroll down. The current code I have in JQuery is not achieving this desired behavior. $('#chatbo ...

Tips for choosing a specific <option> from a <select> tag in Python 3 with Selenium

Hello, I am a newcomer to Python and would like to express my gratitude in advance for your help. Apologies if I state something that seems obvious. I am trying to click on an option that is deeply nested within the HTML structure (not sure if this matter ...

Sharing data between child and parent components in Angular2: a comprehensive guide

I am facing an issue with transferring a range of values from a child component to a parent component. Below are the details of my components: TS: import { Component, EventEmitter, Output, OnChanges, SimpleChanges } from '@angular/core'; @Com ...

Creating multifunctional arrays in HTML tables

My goal is to create tables where each cell changes its class upon being clicked. As I set up the table, I want to track the history of clicked cells in an array. Currently, the history array is stored in the 'clicked' array: array=[1,4,6,9] ...

Troubleshooting a Peculiar Problem with Form Submission in IE10

Please take a look at the code snippet provided below: <!DOCTYPE html> <html> <body> <form name="editProfileForm" method="post" action="profileDataCollection.do"> <input type="text" id="credit-card" name="credit-card" onfocu ...

Buttons moving erratically upon loading of the page

I noticed that my buttons are moving around every time a new page loads. How can I preload the relative positioning or fb api to avoid this issue on each page? Check out my website here. ...

Tips on steering clear of the issue of "Automatic grid alignment" when working with Bootstrap?

I'm attempting to achieve something along the lines of, |--------------Empty space---------------|-----first column(aligned to the right)-----| |---logo---||------Empty space-------|----second column(aligned to the right)---- However, it is automat ...

Discover the steps for highlighting two specific areas on a map using HTML

Is it possible to select two different area maps using the HTML attribute "COORDS" with just one click? For example: <!DOCTYPE html> <html lang="en"> <head> </head> <body> <div class="map"> <MAP name="map1"> ...

Is it possible that JSoup might not retrieve all items?

I'm facing an issue while trying to parse a simple list using JSoup. Strangely, the program seems to only return entries up until those starting with N in the list. I'm puzzled as to why this is happening. Below is the code snippet: public ...

jQuery secret decoder

Recently, I came across a fascinating jquery plugin that had the ability to "expand" a <pre> element horizontally whenever you hovered your mouse over it. Regrettably, the name of this plugin and where to locate it slips my mind... Can anyone provi ...

Tips on wrapping div elements while maintaining equal width in different screen sizes using @media queries

Does anyone have a solution for wrapping divs using @media screen while maintaining equal width on all divs? I've tried using float and inline-block, but can't seem to achieve consistent justified widths. While table-cells maintain equal field wi ...

In React development, a div (button) is visible, but in the production build, it becomes hidden from

I have been working on a website for my job, and I have added a "Gallery" button on top of two slideshows. Everything works perfectly fine on the development build, but when it comes to the production build, the button doesn't show up for some reason. ...