html - 如何将背景图像设置为全长并使文本居中对齐?

标签 html css

我的标题横幅设置为 100% 宽度,但它没有覆盖顶部的所有内容,它看起来像 70%,文本没有设置为居中,当我在 chrome 中检查元素时,它显示 100% 宽度,但在实际显示中它不是。我该如何解决这个问题?

main.html

<div class="row">
    <div class="col-md-12">
        <div class="header-banner">
            <h1>Server</h1>
        </div>
    </div>
</div>

主.css

.header-banner {
    background:url('../img/header_master.jpg');
    width:100%;
    min-height:70px;
    background-repeat: no-repeat;
    text-align: center;
}

最佳答案

试一试:

.header-banner {
        background:url('../img/header_master.jpg');
        width:100%;
        min-height:70px;
        background-repeat: no-repeat;
        text-align: center;
        background-size: cover;
    }

关于html - 如何将背景图像设置为全长并使文本居中对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38706646/

相关文章:

javascript - 如何水平显示子菜单?

php - 在检查元素中显示 0*0 像素的图像

php - 无法在 php 代码中打印 php 变量

jquery - 将图像与最大宽度和最大高度右对齐

html - 如何同步元素的高度

css - 为什么 Bootstrap col-xs- "Horizontal at all times"?

html - 提交的表格未编码 +'s when using method="get"

python - 区分jinja2中的类型

PHP MySQL 图片/数据动态对齐

javascript - 在我的 WebStorm 元素中为 JS 和 CSS 文件创建自动标记的快捷方式