【问题标题】:Thumbnail hover scaling within thumbnail size缩略图大小内的缩略图悬停缩放
【发布时间】:2016-12-17 18:07:44
【问题描述】:

当我将鼠标悬停在拇指上时,我试图获得比例效果,就像在这个 Codepen 示例中一样(第一个拇指,百合效果):

http://codepen.io/intermedion/pen/BQVJEx

我修改了上面的例子,去掉了figure/figcaption,我为拇指网格使用了一个flexbox布局,看这支笔:

http://codepen.io/intermedion/pen/dOKrWQ?editors=1100

<!-- HTML -->
<div class="wrap">
  <div class="row">
    <div>
      <a href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-1.jpg">

          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-1.jpg">

      </a>
    </div>

    <div>
      <a href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-3.jpg">
        <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-3.jpg">
      </a>
    </div>
  </div>
</div>  

/* CSS */ 
.row {
  display: flex;
  flex-flow: row wrap;
  padding: 0 5px;
  font-size: 0;
}

.row div {
  flex: auto;
  width: 160px;
  margin: 6px 12px;
}

.row div img {
  width: 100%;
  height: auto;
}


/*** EFFECTS ***/
.row img {
  position: relative;
  display: block;
  min-height: 100%;
  max-width: 100%;  
}

.row img {
  -webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
  transition: opacity 0.35s, transform 0.35s;

}

.row:hover img {
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-transform: scale(1.15);
  transform: scale(1.15);
}

我尝试了各种选项,包括在拇指上设置大小,添加图形/figcaption - 拇指比例,但超出了缩略图大小,这不是我想要的。

我开始怀疑可能是 flexbox 布局导致缩放超出了渲染的拇指大小,但我不确定。

有没有办法在渲染的拇指中使用 flexbox 布局进行缩放?

【问题讨论】:

    标签: css hover


    【解决方案1】:

    我想你忘记了overflow:hiddendiv

    .row div {
      flex: auto;
      width: 160px;
      margin: 6px 12px;
      overflow: hidden; 
    }
    

    html {
      box-sizing: border-box;
    }
    
    *,
    *:before,
    *:after {
      box-sizing: inherit;
    }
    
    ul {
      list-style-type: none;
    }
    
    a:link { text-decoration: none; } 
    a:visited { text-decoration: none; } 
    a:hover { text-decoration: none;}
    
    
    html {
      background: #2b303b;
      -webkit-font-smoothing: antialiased;
      -moz-osx-font-smoothing: grayscale;
    }
    
    /*** LAYOUT ***/
    
    .wrap {
      max-width: 660px;
      margin: 1.5em auto 1em auto;
      padding: 10px 10px;
      background: #2e333f;
      background-color: rgba(32, 38, 52, 0.6);
      background: #242B3A;
      font-family: "PT Sans", "Helvetica Neue", Arial, sans-serif;
      font-size: 100%;
      color: rgba(127, 133, 147, 0.8);
      border-radius: 5px;
      -webkit-border-radius: 0px 0px 5px 5px;
      -moz-border-radius: 0px 0px 5px 5px;
    }
    
    /*** GRID ***/
    
    .row {
      display: flex;
      flex-flow: row wrap;
      padding: 0 5px;
      font-size: 0;
    }
    
    .row div {
      flex: auto;
      width: 160px;
      margin: 6px 12px;
      overflow: hidden;
    }
    
    .row div img {
      width: 100%;
      height: auto;
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
    }
    
    
    /*** EFFECTS ***/
    .row img {
      position: relative;
      display: block;
      min-height: 100%;
      max-width: 100%;  
    }
    
    .row img {
      -webkit-transition: opacity 0.35s, -webkit-transform 0.35s;
      transition: opacity 0.35s, transform 0.35s;
      
    }
    
    .row div:hover img {
      -webkit-transform: translate3d(0, 0, 0);
      transform: translate3d(0, 0, 0);
      -webkit-transform: scale(1.15);
      transform: scale(1.15);
    }
    
    /*** CAPTIONS ***/
    
    /*
    .grid figure {
      position: relative;
      float: left;
      overflow: hidden;
      margin: 10px 1%;
      min-width: 300px;
      max-width: 480px;
      max-height: 360px;
      width: 48%;
      background: #3085a3;
      text-align: center;
      cursor: pointer;
    }
    */
    /*
    .grid figure img {
      position: relative;
      display: block;
      min-height: 100%;
      max-width: 100%;
      opacity: 0.8;
    }
    */
    <div class="wrap">
      <div class="row">
        <div>
          <a href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-1.jpg">
            
              <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-1.jpg">
           
          </a>
        </div>
        
        <div>
          <a href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-3.jpg">
            <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/jeremiah-wilson-3.jpg">
          </a>
        </div>
      </div>
    </div>  

    【讨论】:

    • 确实,它现在完全按照我的意愿工作,谢谢!
    • 哦,.row:hover img{...} 中的悬停也应该是.row img:hover{...},否则当悬停在一个图像上时,该行中的所有图像将同时缩放。
    猜你喜欢
    • 2010-11-21
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 2012-01-27
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    相关资源
    最近更新 更多