html - 绝对定位以覆盖其他元素但下推其他元素

标签 html css

此时,类“sub-container”覆盖了顶部图像“myimage.png”元素,这很好,但它也覆盖了下面的“main-body-content”元素。

我的问题是,如何只覆盖顶部元素“myimage.png”而不覆盖底部元素“main-body-content”。它应该向下推“主体内容”,而不是覆盖在它上面。

这是我的代码:

   <div class="body">
        <div class="container-position-relative">
            <div class="image-overlay-by-bottom-elements myimage"><img src="myimage.png"></div>
            <div class="overlay-image-above title">Title</div>
            <div class="overlay-image-above-and-push-down-the-main-body-content-below sub-container"> Sub Container </div>
        </div>
        <div class="main-body-content">Main page body content</div>
    </div>


    // css style for myimage
    img {
    position: absolute;
    @include object-fit(cover);
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0.56;
    filter: alpha(opacify=56);
    }

    // css style for Title
    .title {
    color: #ffffff;
    top: 100px;
    z-index: 10;
    height: 40px;
    font-family: Gibson;
    font-size: 40px;
    font-weight: 600;
    font-stretch: normal;
    font-style: normal;
    line-height: 1.2;
    letter-spacing: normal;
    position: absolute;
    left:0;
    right:0;
    }

    // css style for body
    .body {
    wrap {
    display: block;
    padding-bottom: 35%;
    position: relative;
    background-color: #000000;
    }

    // css style for sub-container
    .sub-container {
        top: 100px;
        z-index: 10;
        position: absolute;
    }

最佳答案

试试这个

.container-position-relative{
    position: relative;
    width: 100%;
    min-height: 300px;
}

关于html - 绝对定位以覆盖其他元素但下推其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58828315/

相关文章:

css - 是否有任何特定原因导致filter属性在根元素的background属性中不起作用?

html - 尝试向我的网站添加滚动动画

html - 如何在顶部更大面积的情况下正确布局 flexbox

css - 针对新的不同样式的容器中的多个选择器

html - 具有图像背景的响应宽度 Div 作为全宽标题图像(固定高度)

html - 如何使用 bootstrap 或纯 css 制作响应式断点内容

javascript - Facebook 页面不会自动调整为较小的内容

php - 修改jQuery日历列

javascript - 如何迭代一系列问题和答案

css,我无法像 Safari 中的其他站点一样设置字体 (mac)