What is the best way to adjust the z-index when hovering over an li element

In my <ul>, each <li> contains an image. I want these images to scale and become opaque upon hover. However, the issue is that when they scale, they get covered by the following image. Unsure if the z-index is correctly placed... Below is the CSS code I have:

.artgallery {
    background-color:rgba(255,255,255,0.8);
    color:#fff;
    width:100%;
    padding:0px;
    margin:0;
    height:80%;
    overflow:auto;
    position:absolute;
    top:10%;
}

.artgallery ul {
    list-style: none;
    position:relative;
    text-align: center;
    width: 100%;
    padding-top:5px;
}

.artgallery li {
    position:relative;
    display: inline-block;
    vertical-align: top;
    width:19%;
    opacity:.7;
    transform: scale(1);
    -moz-transform: scale(1);
    -webkit-transform: scale(1);
    transition: all 0.5s;
    -moz-transition: all 0.5s;
    -webkit-transition: all 0.5s;
    -o-transition: all 0.5s;
    z-index:0;
}

.artgallery li:hover {
    opacity:1;
    transform: scale(1.1);
    -moz-transform: scale(1.1);
    -webkit-transform: scale(1.1);
    z-index:100;
}

.artgallery img {
    height: 100px;
    width:100%;
}

.artgallery a {
    margin: 0 0 0 0;
    padding: 0 0 0 0;
}

Here is the corresponding HTML:

<div class="artgallery">        
    <img src="images/art.png" style="width:66px;height:66px;position:absolute;top:2px;left:5px;z-index:2;">
    <ul>
        <li><a href="art/22.jpg" data-lightbox="art" title=" "><img src="art/22_thumb.jpg"></a> </li>
        <li><a href="art/21.jpg" data-lightbox="art" title=" "><img src="art/21_thumb.jpg"></a></li>
        <li><a href="art/20.jpg" data-lightbox="art" title=" "><img src="art/20_thumb.jpg"></a></li>
        <li><a href="art/19.jpg" data-lightbox="art" title=" "><img src="art/19_thumb.jpg"></a>   </li>
        <li><a href="art/18.jpg" data-lightbox="art" title=" "><img src="art/18_thumb.jpg"></a></li>
        <li><a href="art/17.jpg" data-lightbox="art" title=" "><img src="art/17_thumb.jpg"></a></li>
        <li><a href="art/16.jpg" data-lightbox="art" title="WIP"><img src="art/16_thumb.jpg"></a></li>
        <li><a href="art/15.jpg" data-lightbox="art" title=" "><img src="art/15_thumb.jpg"></a></li>
        <li><a href="art/14.jpg" data-lightbox="art" title=" "><img src="art/14_thumb.jpg"></a></li>
        <li><a href="art/13.jpg" data-lightbox="art" title=" "><img src="art/13_thumb.jpg"></a></li>
        <li><a href="art/12.jpg" data-lightbox="art" title="WIP"><img src="art/12_thumb.jpg"></a></li>
        <li><a href="art/11.jpg" data-lightbox="art" title=" "><img src="art/11_thumb.jpg"></a></li>
        <li><a href="art/10.jpg" data-lightbox="art" title="WIP"><img src="art/10_thumb.jpg"></a></li>
        <li><a href="art/9.jpg" data-lightbox="art" title=" "><img src="art/9_thumb.jpg"></a></li>
        <li><a href="art/8.jpg" data-lightbox="art" title=" "><img src="art/8_thumb.jpg"></a></li>
        <li><a href="art/7.jpg" data-lightbox="art" title=" "><img src="art/7_thumb.jpg"></a></li>
        <li><a href="art/6.jpg" data-lightbox="art" title=" "><img src="art/6_thumb.jpg"></a></li>
        <li><a href="art/5.jpg" data-lightbox="art" title=" "><img src="art/5_thumb.jpg"></a></li>
        <li><a href="art/4.jpg" data-lightbox="art" title=" "><img src="art/4_thumb.jpg"></a></li>
        <li><a href="art/3.jpg" data-lightbox="art" title=" "><img src="art/3_thumb.jpg"></a></li>
        <li><a href="art/2.jpg" data-lightbox="art" title="paint doodles"><img src="art/2_thumb.jpg"></a></li>
        <li><a href="art/1.jpg" data-lightbox="art" title="circa 2007"><img src="art/1_thumb.jpg"></a></li>
    </ul>
</div>

Answer №1

The CSS code provided is sufficient, and avoid repeating transform properties on :hover pseudo-class :

.artgallery li:hover{
    opacity:1;        
    z-index:100;
}

Another tip is to add a higher z-index to the hover element img (better safe than sorry) :

.artgallery li:hover img{
    position: relative;        
    z-index:200;
}

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

Guide on emphasizing a div when the page's validity is not true

Is there a way to highlight a specific div when the page.isvalid=false? I can display the error message on page load, but struggling to highlight the required control. I have a JavaScript function that applies an error class to the div, which works fine w ...

Is there a way to stop these symbols (♈♉♊♋♌♍♎♏♐♑♒♓) from being substituted with emojis?

I am currently working on a project involving the simulation of the Prague Astronomical Clock (). My goal is to display the glyphs representing signs of the zodiac, which are in the Unicode range U+263C-2653 along with other astronomical symbols. My prefe ...

Attempting to utilize Flexbox to populate vacant areas

https://i.stack.imgur.com/BhPU0.png Can the yellow square smoothly transition to the empty grey square and beyond in this layout setup? Each flex item represents a component that can utilize either 50% or 100% of the container width, information only know ...

Building an easy-to-use jQuery task list

I'm currently working on a basic to-do list in Javascript, but I've encountered an issue. When I check the checkbox, the style of the adjacent text doesn't change as expected. Instead, it's the heading text that is affected by the chang ...

Is there a way to apply the style property only when a component is hovered in Next.js?

I would like the ability to hover over a component and have it display with unique CSS characteristics. For instance, if I hover on item A, I only want item A to stand out from the rest. Currently, I am using this method of changing the element's bac ...

Is there a way to arrange the components of my form so that the questions are positioned on the left side and the choices are displayed on the right

As I am creating a form, my goal is to align the information within it in a way that places the questions on the left side and the options on the right. I have experimented with utilizing IDs, centering them, and adjusting their positioning from left to r ...

Master the art of displaying complete text when zooming in and elegantly truncating it when zooming out

I am currently working on a data visualization project using d3.js. The tree chart that I have created is functioning well, but I would like the text to react dynamically when zooming in and out. You can find the code for my project on this JSFiddle page. ...

Animate the transition of the previous element moving downward while simultaneously introducing a new element at the top

I currently have a hidden element called "new element" that is controlled by v-if. My goal is to create a button labeled "display" that, upon clicking, will reveal the new element on top after sliding down an old element. How can I achieve this using CSS ...

Using jQuery to reveal and conceal elements upon hover interaction

I have implemented a basic jquery function to display and hide a div when hovering over an anchor. However, the issue I am facing is that the div disappears when I move my cursor away from the anchor tag. I want to be able to interact with the div without ...

The CSS properties intended for ion-button elements are not taking effect

I'm attempting to set a background color when a ion-button is clicked or maintain the ion-ripple effect after it has filled the button in Ionic 4. I experimented with applying custom CSS states in global.scss, but encountered issues where the active ...

Homepage featuring a stacked image background similar to Kickstarter

I am trying to replicate the stacked image effect seen on kickstarter.com. However, I am facing an issue where the images do not overflow on the screen as desired. The arrow indicates the area that needs to be filled with the image. Check out the image he ...

Issues with Laravel 8's datatable scripts causing dysfunction

In my practice with the AdminBSB template, I am facing an issue where the Jquery datatable plugin JS is not functioning properly in my blade template. I aim to achieve a datatable layout similar to this example: https://i.sstatic.net/krfPl.jpg However, t ...

Aligning table data elements within a division

Currently working on revamping a tech night website for my school. I made some changes to the navbar, switching it from the side to the top. However, I'm struggling to get the table data and menu to center properly within the div. If you'd like ...

Issues with navigating sliders

I've encountered a problem with my slider arrows while following a YouTube tutorial. They are supposed to appear next to the picture and testimonial, but instead, they are showing up at the top. This issue wasn't present initially, but after enco ...

Configuration options for content division in a table cell

Please see the following fiddle which I have attempted: http://jsfiddle.net/9LdEc/ code: html: <div id="CorpDealerSearch"> <div class="row"> <div class="left"> Quarter To Date </div&g ...

Why does text display differently in HTML (Firefox) on Ubuntu compared to Windows 7?

When viewing the HTML and CSS code in Firefox on Windows, everything appears fine. However, when I view it in Firefox on Ubuntu, it looks out of place. How can this be corrected? Any suggestions? Additional information: The CSS code used for the text show ...

What is the best way to align sections side by side using Bootstrap?

Hello, I'm currently trying to customize the layout of this Bootstrap webpage to resemble the design shown in this image https://i.sstatic.net/w7i6Z.png. Specifically, I want to display the blog section and the team section side by side. As a beginne ...

iOS exhibits a flashy display of Material Select lighting up

In my attempt to develop a website using Material Design, I encountered an issue with the Material Select component. Whether I utilize MDB (Material Design for Bootstrap) or the Materialize CSS framework, both function well on Windows/OSX/Android devices. ...

Achieving vertical alignment in Bootstrap for card header

I'm troubleshooting a card layout on my Bootstrap page <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" cro ...

JavaScript button click changes the selected row's color in a DataTable

I am looking to dynamically change the color of a row in my Datatable when a specific button is clicked. Here is the HTML code snippet for the rows: <tr role="row" class="odd"></tr> <tr role="row" class="even selected"></tr> & ...