SCSS如何在鼠标悬停时显示此结果

时间:2016-12-03 16:02:50

标签: html sass

如何编码SCSS以在悬停时显示左图像。

HTML

<div class="col-md-4 col-sm-6">
   <div class="reference__content--item">
      <img src="{{ asset($reference->photo->file) }}">
   </div>
</div>

SCSS

.reference {
   &__content {
      margin-bottom: 30px;
      &--item {
         background-color: transparent;
         img {
            margin-top: 30px;
            &:hover {
                background-color: #0000AA;
            }
         }
      }
   }
}

Example

1 个答案:

答案 0 :(得分:1)

我已检查过您的代码,通常现在可以使用。

<强> HTML:

    <div class="col-md-4 col-sm-6">
        <div class="reference__content--item">
            <img src="{{ asset($reference->photo->file) }}">
            <div class="overlay"></div>
        </div>
    </div>

<强> SCSS:

    .reference {
        &__content {
            &--item {
                position: relative;
                display: inline-block;
                img {
                    margin-top: 30px;
                    &:hover {
                        background-color: #0000AA;
                    }
                }
                .overlay {
                    position: absolute;
                    top: 0;
                    left: 0;
                    right: 0;
                    bottom: 0;
                    background-color: rgba(0, 0, 255, 0.6);
                    z-index: 9999;
                    color: white;
                    visibility: hidden;
                }

                // you have to use just the "&" sign instead of reference__content--item
                &:hover>.overlay {
                    visibility: visible;
                }
            }
            &--title {
                font-size: 18px;
            }
        }
    }