背景图像不显示在css中 [英] Background image is not showing in css

查看:104
本文介绍了背景图像不显示在css中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上搜索,发现将 body,html height,width 设置为100%问题,但它没有。
我有这个html:

I have searched on the internet and found that setting body, html height, width to 100% will fix the issue but it did not. I have this html:

<body>
    <div class="container index">
        <div class="row">
            <div class="buttons">

                <!--learn alphabets button-->
                <a>
                    <div class="col-3 learn">
                        <p>
                            Learn
                        </p>
                    </div>
                </a>
            </div><!--buttons end here-->
        </div><!--row ends here-->
    </div><!--container ends here-->

</body>

并在我的css中:

.index{
    background-image: url("../images/index-bg.jpg");
    background-size: cover;
    background-repeat: no-repeat;
}



我已经定义了body和html的宽度和高度:

I have defined the width and height to body and html:

html, body { height: 100%; width: 100%;}

但图片不显示,除非我设置< c $ c> .index 在 px

为什么会这样?

but the image is not showing up unless I set the height of .index in px.
Why is that so?

您的 .index div没有应用高度。背景只会与div包含的内容一样高。

You do not have a height applied to your .index div. The background will only be as tall as the content that div contains.

.index {
    background-image: url("../images/index-bg.jpg");
    background-size: cover;
    background-repeat: no-repeat;
    min-height: 100%;
}

这篇关于背景图像不显示在css中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆