1

我正在使用 Instafeed.js 插件并尝试设置“喜欢”悬停覆盖以填充整个图像框,但是,我正在努力将高度设置为 100%。

我试图避免将容器的高度设置为像素值,因为整个插件当前都是响应式的。

我环顾四周并尝试了不同的值组合displayposition但主要是反复试验。

CSS:

#instafeed {
  width: 100%;
  margin-bottom: 80px;
}
#instafeed a {
  position: relative;
}
#instafeed .ig-photo {
  width: 25%;
  vertical-align: middle;
}
#instafeed .likes {
  width: 100%;
  height: auto;
  top: 0;
  left: 0;
  right: 0;
  position: absolute;
  background: #f18a21;
  opacity: 0;
  font-family: 'LinotypeUniversW01-Thin_723604', Arial, sans-serif;
  font-size: 28px;
  color: #ffffff;
  line-height: 100%;
  text-align: center;
  text-shadow: 0 1px rgba(0, 0, 0, 0.5);
  -webkit-font-smoothing: antialiased;
  -webkit-transition: opacity 100ms ease;
  -moz-transition: opacity 100ms ease;
  -o-transition: opacity 100ms ease;
  -ms-transition: opacity 100ms ease;
  transition: opacity 100ms ease;
}
#instafeed a:hover .likes {
  opacity: 0.8;
}

演示:http: //jsfiddle.net/rc1wj5t9/

任何帮助/建议将不胜感激!

4

2 回答 2

3

这是因为锚元素是inline默认的,这意味着它们不会继承其子img元素的高度。

一种可能的解决方案是将display锚元素的 设置为inline-block,并将宽度指定为25%。然后对于子img元素,设置a max-width100%

更新示例

#instafeed a {
    position: relative;
    display: inline-block;
    max-width: 25%;
}
#instafeed .ig-photo {
    max-width: 100%;
    vertical-align: middle;
}
#instafeed .likes {
    width: 100%;
    height: auto;
    top: 0; right: 0;
    bottom: 0; left: 0;
}

为了使文本居中,我使用了一种技术,将我以前的答案中的文本垂直/水平居中。

#instafeed .likes > span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
    white-space: nowrap;
}
于 2015-11-20T03:43:14.517 回答
1

这是我修复它的方法。

CSS

#instafeed {
  width: 100%;
  margin:0px;
}
#instafeed a {
  position: relative;
  display:inline-block;
  float:left;
  width: 25%;
}
#instafeed .ig-photo {
  width: 100%;
  vertical-align: middle;
}
#instafeed .likes {
  position: absolute;
    width: 100%;
  opacity: 0;
  font-family: 'LinotypeUniversW01-Thin_723604', Arial, sans-serif;
  font-size: 28px;
  color: #ffffff;
  text-align: center;
  top: 50%;
  transform: translateY(-50%);  
  text-shadow: 0 1px rgba(0,0,0,0.5);
  -webkit-font-smoothing: antialiased;
  -webkit-transition: opacity 100ms ease;
    -moz-transition: opacity 100ms ease;
    -o-transition: opacity 100ms ease;
    -ms-transition: opacity 100ms ease;
    transition: opacity 100ms ease;
    z-index:10;
}
#instafeed a:hover .likes {
  opacity: 1;
}
#instafeed a:hover::after{
    content:"";
    position:absolute;
    width: 100%;
    height: 100%;
    top: 0; left: 0;
    background: #f18a21;
    opacity:0.7;
    z-index: 5;
}

更新的小提琴

于 2015-11-20T03:47:57.693 回答