将背景图像居中

发布于 2024-08-12 01:21:00 字数 673 浏览 4 评论 0原文

在此处输入图像描述

请看一下上面的屏幕截图,我想将黑色背景的图像居中,但是我在底部有一些空白。请任何人帮我解决这个问题。

CSS

.bgimg {
    background: url('../images/GBS-Chronicle-Background-1.png') black no-repeat center;
}
div#cont {
    height: 672px;
}

HTML

<body class="bgimg">
<div id="doc2">
    <div id="hd"></div>
    <div id="bd">
        <div id="cont">
            <div class="middle">
                <p> hi hello </p>
            </div>
        </div>
    </div>
    <div id="fd"></div>
</div>  

enter image description here

Please have a look at the above screen shot, I would want to center an image with black background, but i'm getting some white space at the bottom. Please could any one help me to fix this.

CSS

.bgimg {
    background: url('../images/GBS-Chronicle-Background-1.png') black no-repeat center;
}
div#cont {
    height: 672px;
}

HTML

<body class="bgimg">
<div id="doc2">
    <div id="hd"></div>
    <div id="bd">
        <div id="cont">
            <div class="middle">
                <p> hi hello </p>
            </div>
        </div>
    </div>
    <div id="fd"></div>
</div>  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

心奴独伤 2024-08-19 01:21:00

尝试添加这个:

html,body { height:100%; }

Try adding this:

html,body { height:100%; }
归属感 2024-08-19 01:21:00

尝试在 .bgimg 类上设置 height:100%;

编辑:您可能还需要将 padding:0;margin:0; 设置为您的 .bgimg 类,以确保安全。

Try setting height:100%; on your .bgimg class.

Edit: You may also want to set padding:0;margin:0; to your .bgimg class as well just to make sure.

梦毁影碎の 2024-08-19 01:21:00

我猜 GBS-Chronicle-Background-1.png 不够高。您可以将背景颜色添加为黑色或与 Y 一起重复图像。

I guess GBS-Chronicle-Background-1.png is not high enough. you can either add background color to black or repeat the image along with Y.

海的爱人是光 2024-08-19 01:21:00

尝试更改背景规则的顺序,使颜色排在第一位。

background: black url('../images/GBS-Chronicle-Background-1.png') no-repeat center;

Try changing the order of your background rule so the color comes first.

background: black url('../images/GBS-Chronicle-Background-1.png') no-repeat center;
吃不饱 2024-08-19 01:21:00

也试试这个(正如上面建议的那样):

body {color:#000000;}

另外:我建议也注释掉内容 div 的高度。和/或将内容 div 的 bkg-color 设置为与正文相同的颜色。希望有帮助! :)

try this too (as has been suggested above):

body {color:#000000;}

Also: I would suggest commenting out the Height of your content div as well. And/or setting the bkg-color of the content div to the same color as the body. Hope that helps! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文