htmlcssgoogle-chromez-index

Z-Index Flickering in Chrome on Hover


I'm trying to create a hover button using the following code and it works relatively okay in all browsers except Chrome:

<div id="blur" class="et_pb_module et-waypoint et_pb_image et_pb_animation_off et_pb_image_0 et_always_center_on_mobile et-animated">
    <a href="http://vina.typesetdesign.com/wines/reserva/reserva-sauvignon-blanc/">
    <img alt="" src="http://vina.typesetdesign.com/wp-content/uploads/2015/11/2015_11_17Vina_Echeverria_Reserva_Sauvignon_Blanc_V1.png">
    </a>
    </div>

        #blur img {
        -webkit-transition: all 1s ease;
        -moz-transition: all 1s ease;
        -o-transition: all 1s ease;
        -ms-transition: all 1s ease;
        transition: all 1s ease;
    }

    #blur img:hover {
        opacity: .4;
        z-index: 1;
    }

    #blur a:hover:before {
        background-color: #6d8e3b;
        color: #fff;
        content: "Learn More";
        display: block;
        font-size: 12px;
        margin-left: auto;
        margin-right: auto;
        opacity: .9 !important;
        padding: 18px;
        position: relative;
        top: 20em;
        width: 70px;
        z-index: 2;
        margin-top: -3em;
    }

For some reason, Chrome won't let you hover over the button without it glitching out and flickering super badly. Is there an easy way around this without having to add in a separate button?

Live Page: http://vina.typesetdesign.com/wines/varietal/

Fiddle: https://jsfiddle.net/35txpy8v/


Solution

  • It's flickering because the element moves while you hover over it. The reason the element is moving is because of the pseudo element's positioning. To work around this, I'd suggest absolutely positioning the pseudo element relative to the parent element. In doing so, the pseudo element's position won't have any effect on the parent element.

    Updated Example

    #blur img {
      -webkit-transition: all 1s ease;
      -moz-transition: all 1s ease;
      -o-transition: all 1s ease;
      -ms-transition: all 1s ease;
      transition: all 1s ease;
      position: relative;
    }
    #blur img:hover {
      opacity: .4;
      z-index: 1;
    }
    #blur a:hover:before {
      content: "Learn More";
      background-color: #6d8e3b;
      position: absolute;
      top: 50%;
      margin-top: -50px;
      color: #fff;
      font-size: 12px;
      opacity: .9;
      padding: 18px;
      width: 70px;
      z-index: 2;
    }