【问题标题】:SCSS/CSS hover on imageSCSS/CSS 悬停在图像上
【发布时间】:2016-09-02 02:41:44
【问题描述】:

我想将鼠标悬停在一个盒子上并转换图像的比例 (1.1)。但问题是我在图像前面有一个文字。因此,如果我将鼠标悬停在文本上它不起作用

我想将鼠标悬停在框上的任意位置并缩放图像。

这是我的代码

HTML

<div class="col-md-12 club-index__box">
   <a href="{{ path('toro_web_club_show', {'id': r.id}) }}">
      <div class="club-index__box--nation">
         <div class="club-index__box--image">{{ toro_image(r.coverImage, '1050x250') }}</div>
         <div class="club-index__box--text">
            <span class="club-index__box--title">{{ r.name }}</span>
            <span class="club-index__box--sub-title">ทีมชาติไทย 2016 , ผู้จัดการทีม , รายชื่อผู้เล่น</span>
         </div>
      </div>
   </a>
</div>

SCSS

.club-index {
   &__box {
       margin-top: 30px;
       &--nation {
           position: relative;
           display: block;
           width: 100%;
           height: 250px;
           margin: 0 auto;
           background-color: #18202d;
           text-align: center;
           overflow: hidden;
       }
       &--image {
           position: absolute;
           transition: all 1s ease-in-out 0s;
           -moz-transition: all 1s ease-in-out 0s;
           -webkit-transition: all 1s ease-in-out 0s;
           -o-transition: all 1s ease-in-out 0s;
           &:hover {
               transform: scale(1.1);
               -moz-transform: scale(1.1);
               -webkit-transform: scale(1.1);
               -o-transform: scale(1.1);
           }
       }
       &--text {
           position: relative;
           z-index: 1;
       }
       &--title {
           padding-top: 75px;
           font-size: 30px;
           color: #fff;
           text-align: center;
           &:hover{
               transform: scale(1.1);
               -moz-transform: scale(1.1);
               -webkit-transform: scale(1.1);
               -o-transform: scale(1.1);
           }
       }
       &--sub-title {
           margin-top: 20px;
           font-size: 16px;
           color: #fff;
           text-align: center;
           &:hover{
               transform: scale(1.1);
               -moz-transform: scale(1.1);
               -webkit-transform: scale(1.1);
               -o-transform: scale(1.1);}}}}
           }
       }
   }
}

【问题讨论】:

    标签: html css sass


    【解决方案1】:

    不是在图像悬停时缩放图像而是在其父元素悬停时缩放图像,包括图像和文本

     &--nation:hover > image {
              //scale to 1.1
     }
    

    编辑:你的代码会像

        .club-index {
           &__box {
               margin-top: 30px;
               &--nation {
                   position: relative;
                   display: block;
                   width: 100%;
                   height: 250px;
                   margin: 0 auto;
                   background-color: #18202d;
                   text-align: center;
                   overflow: hidden;
    
               }
               &--nation:hover > &--image {
                       transform: scale(1.1);
                       -moz-transform: scale(1.1);
                       -webkit-transform: scale(1.1);
                       -o-transform: scale(1.1);
                   }
               &--image {
                   position: absolute;
                   transition: all 1s ease-in-out 0s;
                   -moz-transition: all 1s ease-in-out 0s;
                   -webkit-transition: all 1s ease-in-out 0s;
                   -o-transition: all 1s ease-in-out 0s;
               }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 2015-06-08
      • 2018-10-16
      • 2021-12-02
      • 2016-01-27
      • 2018-09-12
      • 2013-10-30
      相关资源
      最近更新 更多