我想将背景图像添加到CSS类中,但是没有显示。
我已经尝试过增加高度和宽度。

<div class="landing1">
  <h2>The Lnad OF Programming</h2>
  <p>get involved</p>
</div>


<style>
  body,
  html {
    margin: 0;
    size: 100%;
  }

  .landing1 {
    margin: 3px;
    text-align: center;
    background-image: url(imgs/bg.jpg);
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    width: 400px;
    height: 500px;
  }
</style>

背景图像未显示。

最佳答案

这是工作。您给的图像路径错误



body , html{
margin:0;
size:100%;
}

.landing1{
margin:3px;
text-align:center;
background-image:url(http://placekitten.com/500/500);
background-repeat: no-repeat;
background-size: cover;
background-position:center;
width:400px;
height:500px;
}

<div class="landing1">
    <h2>The Lnad OF Programming</h2>
    <p>get involved</p>
</div>

关于html - 如何将背景图像添加到CSS类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54670390/

10-12 07:22
查看更多