0

I want to add a background image to a CSS class but it dosn't show up.

I've already tried to add height and width.

<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>

the background image isn't show up.

4
  • 2
    Check image path is correct or not Commented Feb 13, 2019 at 12:39
  • it works perfect please check your path:jsfiddle.net/b7vj1ufa Commented Feb 13, 2019 at 12:41
  • Your image path is not correct... make them correct, your image will be show. Commented Feb 13, 2019 at 12:42
  • i double checked the image path, it's correct. Commented Feb 13, 2019 at 12:46

1 Answer 1

1

It is working. You are giving the image path wrong

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>

Sign up to request clarification or add additional context in comments.

11 Comments

sorry i forgot to add that i tried to do that as well.
Quotes not needed
no, i tried to put the image in the same folder with the index.html file
well, it worked when i used (placekitten.com/500/500). but it still not showig when i try from a local file :(
it worked when i added 'url(../imgs/bg.jpg)' , thanks alot!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.