html - 部分重叠CSS中的两个背景图像

标签 html css twitter-bootstrap image

我试图在 CSS 中重叠两个图像:第一个是主菜单的“背景”图像,第二个是首页的“封面”。问题是第一个是透明的 png,它需要显示在封面上方(现在,它不会超出 div 容器)。

现在的结果是这样的:

Menu image

但是第一张图片,#menu .container-fluid 下的图片是这样的:

Header image

当前代码:

HTML

<section>
    <div id="menu">
        <div class="container-fluid">
            <!-- Content of menu -->
        </div>
    </div>
    <div id="portada">
        <figure class="proporcion-fija-indice"></figure>
    </div>
</section>

CSS

.proporcion-fija-indice {
  display: block;
  margin: 0;
  padding-top: 48.30%; /* 2026px/4194px = 0.4830 */
  background-image: url('../img/portada.jpg');
  background-size: cover;
  background-position: center center;
}

#menu .container-fluid {
  background-image: url('../img/header.png');
  min-height: 125px;
}

关于如何实现预期结果的任何想法?

最佳答案

您是否尝试过将 header 调高,并在 proporcion-fija-indice 上设置负边距顶部?

.proporcion-fija-indice {
  display: block;
  margin: 0;
  padding-top: 48.30%; /* 2026px/4194px = 0.4830 */
  background-image: url('../img/portada.jpg');
  background-size: cover;
  background-position: center center;
  margin-top:-50px;
}

#menu .container-fluid {
  background-image: url('../img/header.png');
  min-height: 150px;
}

关于html - 部分重叠CSS中的两个背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50022464/

相关文章:

html - 使用 flex-grow 和 flex-wrap 将元素拆分到新行

html - 是否允许在链接内嵌套链接?

html - 整页图像问题

html - 为 Bootstrap 导航栏元素添加白色背景

css 背景颜色不会显示

html - 调整浏览器图像大小时背景图像部分消失

css - 使边框高度相对于父高度

html - 中间有点的水平线

html - 牢记响应性的内容和页脚间距

javascript - 如何在同一页面上的多个按钮上打开一个 Bootstrap 模式?