html - 容器 Bootstrap 的绝对位置

标签 html css containers positioning absolute

我在将文本与容器正确对齐时遇到了问题。我需要把它放在图片上的位置,但文字总是放在页面的最右边。

enter image description here

你能帮我吗?谢谢你!

HTML:

<header>
    <div class="container">
        <div class="header-text">
            <h3>My aligned heading</h3>
        </div>
    </div>
</header>

SCSS:

header {
    width: 100%;
    margin-top: 80px; 
    height: 518px;
    background-image: url(../img/header.jpg);
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    position: relative;

    .container {

        .header-text {
            position: absolute;
            right: 0;
            bottom: 30px;

            h3 {
                font-weight: 400;
                font-size: 18px;
                text-transform: uppercase;
                padding: 10px 10px 10px 45px;
                border: 0;
                border-radius: 0;
                background-color: #fff;
                text-align: right;
            }
        }
    }
}

最佳答案

您应该将 position:relative; 设置为 .container 而不是 header。绝对定位的元素对于第一个相对的父元素来说是绝对定位的。

关于html - 容器 Bootstrap 的绝对位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40942366/

相关文章:

html - Grid CSS 没有正确布局区域

html - 文本不环绕另一个 div

image - 我需要删除以前构建的未使用的Docker镜像/容器吗?

javascript - 从它的中心动画div

java - jsf commandLink 没有正确更新 url

jquery - 是否可以使用 jquery、css 等更改图像部分的颜色

c - 如何使用类似容器的方式在 C 中添加可变长度数据

javascript - Bootstrap : Button appearance changes upon hover

html - 你能控制或定位包装元素的样式吗?

azure - Docker 容器 VS PCF