简体   繁体   English

浮动的缩略图库,悬停时有额外的缩略图内容。 如何使悬停的缩略图与邻居重叠?

[英]floated thumbnail gallery, with extra thumbnail content on hover. How to allow hovered thumbnail to overlap neighbors?

I have a gallery of thumbnail images. 我有一个缩略图画廊。 Below each image, I display the thumbnail title: 在每个图像下方,我显示缩略图标题:

<div class='gallery'>
  <div class='thumb'>
    <div class='thumbimage'></div>
    <div class='thumbtitle'></div>
  </div>
  <div class='thumb'>
    <div class='thumbimage'></div>
    <div class='thumbtitle'></div>
  </div>
</div>

The thumbnails float left, in a grid: 缩略图在网格中向左浮动:

.thumb {
  float: left;
}

The thumbtitles are shortened to fit on one line: 缩略图标题缩短为适合一行:

.thumbtitle {
  line-height: 1.25em;
  min-height: 1.25em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

When the user hovers over a thumbnail, the abbreviated thumbtitle is replaced with the full thumbtitle: 当用户将鼠标悬停在缩略图上时,缩写的缩略图将替换为完整的缩略图:

.thumb:hover .thumbtitle {
  height: auto;
  line-height: 1.25em;
  white-space: normal;
}

If the full thumbtitle does not fit on one line, then the hovered thumbnail box expands downward to accommodate the full title. 如果完整的缩略图标题不适合一行,则悬停的缩略图框将向下扩展以容纳完整的标题。

Here is my problem: 这是我的问题:

When the hovered thumbnail expands downward, the thumbnail below shifts right to get out of its way. 当悬停的缩略图向下扩展时,下面的缩略图会向右移动以摆脱干扰。 This is not the behavior I want. 这不是我想要的行为。 I would like the expanded thumbnail to overlap, rather than push away, the thumbnail below. 我希望展开的缩略图重叠,而不是推开下面的缩略图。 That is, I want the hovered thumbnail box to expand downward without causing any of the other thumbnails to move. 也就是说,我希望悬停的缩略图框向下扩展而不会导致其他任何缩略图移动。

Is this possible? 这可能吗?

You could add 您可以添加

.thumbtitle {
    position:absolute;
}

in order to remove them from the flow of the document, and 为了将它们从文档流中删除,并且

.thumb {
    position:relative;
}

to position .thumbtitle relatively to .thumb . .thumbtitle相对于.thumb

This way you can also add 这样您还可以添加

.thumbtitle {
    max-width:100%; /* or width:100% */
}

Finally, add 最后,添加

.thumb:hover .thumbtitle {
    z-index:1;
}

to make it overlap the following elements. 使它与以下元素重叠。

Demo : http://jsfiddle.net/ANvvR/ 演示http : //jsfiddle.net/ANvvR/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM