html - 添加 div 后图像移出容器

标签 html css overlay

所以我的网站有 3 张横跨整个宽度的图片,每张图片使用 33.33% 的宽度和固定的高度 (800px)。我想在每个单独的图像上创建淡入淡出叠加层,但是一旦我将一些 div 添加到图像的 html 代码 2,即使我没有添加任何空间,图像也会向下移动。有什么想法吗?

How it should behave

What happens upon adding new divs

这是没有任何新 div 的代码,关于如何解决这个问题有什么想法吗?

<div id="content">
        <img src="images/phantom.png"alt="An image showing a male actor performing during the musical Phantom of the Opera" class="musicalimage">
        <img src="images/lion_king.png" alt="An image showing a male actor performing during the musical Lion King" class="musicalimage">
        <img src="images/wicked.png" alt="An image showing a female actor performing during the musical Wicked" class="musicalimage">   
</div>`

#content {
    height: 800px;
    width: 100%;
    font-size: 0px;

}

.musicalimage {
    width: 33.33%;
    height: 800px;
    display: inline;

最佳答案

只需将 display: flex 添加到 #content

#content {
  height: 800px;
  width: 100%;
  font-size: 0px;
  display: flex;
}

.musicalimage {
  width: 33.33%;
  height: 800px;
  display: inline;
}
<div id="content">
  <img src="images/phantom.png" alt="An image showing a male actor performing during the musical Phantom of the Opera" class="musicalimage">
  <img src="images/lion_king.png" alt="An image showing a male actor performing during the musical Lion King" class="musicalimage">
  <img src="images/wicked.png" alt="An image showing a female actor performing during the musical Wicked" class="musicalimage">
</div>`

关于html - 添加 div 后图像移出容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43821855/

相关文章:

javascript - 如何在html中按下回车键时调用javascript函数

javascript - 单击取消按钮后清除选中的复选框

html - 使用 CSS 删除额外的换行符标签

javascript - 如何使用 JavaScript 获取 HTML Table 中 td 内的链接文本?

html - 使用 SCSS 在日历中发布样式化多日期事件

jquery - 覆盖容器应在单击时关闭,但如果单击 anchor 或输入子项则不会关闭

php - 如何使用 CSS 更改网站页面的不同背景图像?

jquery - 垂直对齐具有不同高度的 float DIV?

android - 如何保持flutter应用程序在后台运行(防止被杀死)

image - ffmpeg 缩放输入图像