html - 使出现在多个图像上 HTML/CSS

标签 html css

当我尝试在多张图片上放置文字时,它只出现在第一张图片上,因此只是重叠。我不确定为什么要这样做。我是使用 HTML/CSS 的初学者。演示可在 https://jsfiddle.net/mt4wc8xL/ 获得.只出现“文本二”而不出现“文本一”

HTML:

    <div class="container">
        <div class="thumbnail">
            <div class="movie">
                <a href="http://google.ca">
                    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSYxGcPfqYK-tTFRFqZFMJ761adVBqV0_3N-cVltJcod_PfkTql" alt="dark knight"/>
                    <span class="text">The Dark Knight</span>
                </a>
            </div>
            <div class="movie">
                <a href="http://google.ca">
                    <img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSYxGcPfqYK-tTFRFqZFMJ761adVBqV0_3N-cVltJcod_PfkTql" alt="shutter island"/>
                    <span class="text">The Dark Knight</span>
                </a>
            </div>
        </div>
    </div>

CSS:

  .container {
    background: white;
    position: absolute;
    height: 19em;
    width: 45em;
    border: 1px solid black;
    overflow-x: hidden;
    overflow-y: hidden;
    white-space: nowrap;
}

img {
  max-width: 100%;
}

.spacing{
  position: absolute;
  top: 1em;
  left: 1em;
  width: 225px;
  height: 220px;
}

.movie{
  width: 100%;
  height: 100%;
  display: inline-block;
}

.text{
  position: absolute;
  bottom: -3em;
  left: 0;
  display: inline-block;
  padding: 15px 5px 5px;
  width: 170px;
  color: white;
  font-size: 15px;
  text-shadow: rgba(0,0,0,0.5) 1px 1px 0;
  font-family: sans-serif;

  background-color: black;
  background-position: left-bottom;
  background-repeat: no-repeat;
  background-size: 100% 100%;
}

最佳答案

position: absolute 修复到最近的具有 position: relative

的祖先
.movie{
  width: 100%;
  height: 100%;
  display: inline-block;
  position: relative; /* add this */
}

https://jsfiddle.net/mt4wc8xL/3/

关于html - 使出现在多个图像上 HTML/CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33600908/

相关文章:

html - CSS 背景图像的浏览器问题,无法在 Chrome 中完美显示

javascript - 为什么显示:flex do not respect shadow root border?

html - 为什么有些@media 没有被阅读而不是非@media 对应物?

JavaScript 和 CSS : How to log position of a div between css translate start and end

javascript - 如何使用女巫设置为百分比的jquery直接获取转换的css值

css - 如何使 Bootstrap 轮播中心

javascript - 我会在我的JavaScript中添加什么以使渐变交替显示。

用于编辑 LESS CSS 变量的 Javascript 库?

html - 向左浮动与向右浮动 - 为什么顺序会改变?

javascript - 如何淡出然后直接到新页面