html - 顶级横幅文字叠加对齐问题

标签 html css web

我正在尝试在带有透明边框背景的图像背景上创建一种带有文字的顶部横幅,但不幸的是,我似乎无法正确对齐它。它一直倾斜到页面的右端。有什么想法吗?

这是我的代码示例,正如您将看到的,我试图重置 bor 类的边距,认为它可能有所帮助,但实际上并没有做任何事情。我还尝试重置代码其他部分的边距,但没有任何效果。也许是定位问题,但我似乎无法让它发挥作用。

CSS

.full{
    min-height: 100%;
        background-color: white;
    /*background-image: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.3) 90%), url("america/cservice.jpeg");*/
    /*background-blend-mode: lighten;*/
    padding-top:25px ;
    color: #5a5a5a;
    /*color: black;*/
    padding-bottom: 20px;
    text-align: center;
    align-items: center;
    border-top: 5px solid rgba(0, 0, 102, 0.5);
    border-bottom: 5px solid rgba(0, 0, 102, 0.5);
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
}


.image{
    width: 100%;
    height: 280px;
    background-image: url(america/news2.png);
    background-size: cover;
    background-repeat: no-repeat;
    position: relative;
    padding-top: 20px;
    padding-bottom: 20px;
}

.bor {
    position: absolute;
    border: 5px solid;
    border-color: rgba(255, 255, 255, 0.5);
    padding-top:;
    padding-bottom:;
    background-color: rgba(133, 133, 173, 0.4);
    margin-left: 0px;
    margin-right: ;
}

h2 {
    position: absolute;
    width: 100%;
    color: black;
    font-size: 40px;
    padding-top: 85px;
}

h4 {
    position: relative;
    width: 100%;
    color: white;
    font-size: 30px;
    padding-top: 155px;
    font-stretch: ultra-expanded;
}

b{
    border: 5px solid black;
    padding-right: 25px;
    padding-left: 25px;
    margin-left: 20px;
    margin-right: 20px;
    color: white;
    font-weight: 900;
    font-size: 40px;
}
HTML

<div class="full">
        <div id="section">
            <h1 class="text-center">&mdash;News Feed&mdash;</h1>
            <br>
            <hr>

            <div class="image">
                <center><span class="bor">
                    <h2>Weekly<b>Report</b></h2>
                    <br>
                    <h4>Catch up on all the latest news regarding the world</h4>   
                </span></center>
            </div>

        </div>
</div>

最佳答案

这是一个工作示例:

.full{
    min-height: 100%;
        background-color: white;
    /*background-image: linear-gradient(to right, rgba(255, 255, 255, 1) 0%, rgba(255, 255, 255, 0.3) 90%), url("america/cservice.jpeg");*/
    /*background-blend-mode: lighten;*/
    padding-top:25px ;
    color: #5a5a5a;
    /*color: black;*/
    padding-bottom: 20px;
    text-align: center;
    align-items: center;
    border-top: 5px solid rgba(0, 0, 102, 0.5);
    border-bottom: 5px solid rgba(0, 0, 102, 0.5);
    font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
}


.image{
    width: 100%;
    height: 280px;
    background-image: url(america/news2.png);
    background-size: cover;
    background-repeat: no-repeat;
    position: relative;
    padding-top: 20px;
    padding-bottom: 20px;
    display: block;
    margin: 0 auto;
}

.bor {
    position: absolute;
    border: 5px solid;
    border-color: rgba(255, 255, 255, 0.5);
    padding-top:;
    padding-bottom:;
    background-color: rgba(133, 133, 173, 0.4);
    left: 0;
    right: 0;
}

h2 {
    position: absolute;
    width: 100%;
    color: black;
    font-size: 40px;
    padding-top: 85px;
}

h4 {
    position: relative;
    width: 100%;
    color: white;
    font-size: 30px;
    padding-top: 155px;
    font-stretch: ultra-expanded;
}

b{
    border: 5px solid black;
    padding-right: 25px;
    padding-left: 25px;
    margin-left: 20px;
    margin-right: 20px;
    color: white;
    font-weight: 900;
    font-size: 40px;
}
<div class="full">
        <div id="section">
            <h1 class="text-center">&mdash;News Feed&mdash;</h1>
            <br>
            <hr>

            <div class="image">
                <center><span class="bor">
                    <h2>Weekly<b>Report</b></h2>
                    <br>
                    <h4>Catch up on all the latest news regarding the world</h4>   
                </span></center>
            </div>

        </div>
</div>

您遇到了问题,因为您的 .bor 类具有绝对位置。这意味着您必须使用 topbottomleftright 指定其父项中的位置特性。

希望对您有所帮助!

关于html - 顶级横幅文字叠加对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45791954/

相关文章:

google-maps - 如何在谷歌地图或其他 map 站点的页面中排列 div

c# - 同一 Azure Web 角色中的两个 Web 项目?

angular - 如何使用 grunt 部署 Angular 2?

html - 当我们有 iframe 时为什么要使用 Shadow DOM?

javascript - Canvas strokeStyle粗细

html - 如果设置了相邻 div 的背景颜色,则 Div 不会在相邻 div 上放置阴影

javascript - 我们如何使用 jquery/javascript 插件在文本框下方显示错误消息?

html - ".cssClass object"和 "object.cssClass"之间的 CSS 差异

javascript - Bootstrap 3 Accordion 折叠在 iphone 上不起作用

html/css定位三个文本框