【问题标题】:Responsive hover for responsive image响应式图像的响应悬停
【发布时间】:2017-03-30 02:57:06
【问题描述】:

如何做响应式悬停?

这是一个很好的悬停示例,非常适合我的屏幕尺寸,而这不是响应式悬停示例

这是我的代码

HTML

  <div class="product-img-list">
    <%= link_to product_path(product), class: 'product_link' do %>
    <%= image_tag(product.image_url, class: "img-responsive",  size: "300x250") %>
    <% end %>
    <span class="product-img-text"><span>code</span></span>
  </div>

CSS

span.product-img-text {
  background: rgba(0,0,0,0.5);
  color: white;
  cursor: pointer;
  display: table;
  height: 80px;
  left: 15px;
  position: absolute;
  top: 230px;
  width: 291px;
  opacity: 0;
  -webkit-transition: opacity 500ms;
  -moz-transition: opacity 500ms;
  -o-transition: opacity 500ms;
  transition: opacity 500ms;
}

.product-img-list:hover span.product-img-text {
  opacity: 1;
}

span.product-img-text span {
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}

.img-responsive {
  list-style-type: none;
  margin: 0;
  padding: 0;
  text-align: center;
}

.product-img-list.img-responsive {
  display: inline-block;
  margin: 0 1em 1em 0;
  position: relative;
}

感谢您的帮助

【问题讨论】:

    标签: image css hover


    【解决方案1】:

    我会说你必须让.product-img-text 具有响应性(而不是使用硬编码尺寸

    类似下面的

    span.product-img-text {
      background: rgba(0,0,0,0.5);
      color: white;
      cursor: pointer;
      display: table;
      position: absolute;
    
      height: 25%; /*assuming text is not that much*/
      left: 1em; /*to account for margin*/
      right:1em /*to account for margin*/
      bottom: 0; /*add it to bottom of image*/
    
      opacity: 0;
      -webkit-transition: opacity 500ms;
      -moz-transition: opacity 500ms;
      -o-transition: opacity 500ms;
      transition: opacity 500ms;
    }
    

    如果不是,您必须将.product-img-list 定位为realtive

    .product-img-list{position:relative}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多