当<figcaption>的内容宽度超过<img>同级元素的宽度时,使其呈现滚动条。

3
我正在尝试使<figcaption>元素在其内容宽度超过<img>同级元素的宽度时呈现滚动条,通常是当内容为长URL或非常长的单词时。

以下代码源自此答案,它可以在IE 11和Edge 15中正常工作,但在Firefox 55和Chrome 61中无法正常工作:

* {
  outline: 1px solid red;
}

figure {
  display: table;
  max-width: 100%;
}
  
figure img {
  vertical-align: top;
}
  
figure figcaption {
  display: table-caption;
  caption-side: bottom;
  overflow: auto;
}
<figure>
  <img src="//via.placeholder.com/220x100" alt="">
  <figcaption>Long word in figure caption Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatak</figcaption>
</figure>


在IE 11和Edge 15中的外观:https://i.stack.imgur.com/DPIUa.png - user8686418
1个回答

0

我找到了一个基于答案的解决方案,我将其应用于原始问题中的代码片段:

* {
  outline: 1px solid red;
}

figure {
  display: inline-block;
  position: relative;
  margin: 0 auto;
  max-width: 100%;
}

figure img {
  height: auto;
  max-width: 100%;
  vertical-align: top;
}

figure figcaption {
  left: 0;
  overflow: auto;
  position: absolute;
  right: 0;
}
<figure>
  <img src="//via.placeholder.com/220x100" alt="">
  <figcaption>Long word in figure caption Lopadotemachoselachogaleokranioleipsanodrimhypotrimmatosilphioparaomelitokatak</figcaption>
</figure>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接