Home > Blockchain >  Why is an image not showing in a div
Why is an image not showing in a div

Time:07-03

beginner here! I am following a series of HTML and CSS by Dani Krossing on YouTube, and I followed his series. I reached his video on image in HTML and imported images using div. However for some reason, it's not displaying in my website. I followed the tutorial to a tee but to no avail. Please help me. Here is the HTML code:

* {
  margin: 0;
  padding: 0;
  font-family: Arial, Helvetica, sans-serif;
}

body {
  background-color: #eee;
}

.wrapper {
  margin: 0 auto 0 60px;
  width: 1000px;
}

nav {
  background-color: #fff;
  width: 100%;
  height: 100px;
}

ul {
  line-height: 100px;
  margin: 0;
}

ul li {
  display: inline-block;
  float: left;
}

ul li a {
  text-decoration: none;
  color: #1e1e1e;
  display: block;
  padding: 0px 20px;
}

ul li a:hover {
  color: darkred;
}

.img-lightning {
  width: 400;
  height: 229;
  background-image: url(images/lightning.jpg);
}
<nav>
  <div >
    <ul>
      <li>
        <a href="index.html">Home</a>
      </li>
      <li>
        <a href="about.html">About Me</a>
      </li>
      <li>
        <a href="portfolio.html">Portfolio</a>
      </li>
      <li>
        <a href="contact.html">Contact me</a>
      </li>
    </ul>
  </div>
</nav>
<div >
  <h1>Front Page</h1>
  <div ></div>
</div>

Here is the image of the website having the error: The website

CodePudding user response:

You wrote width and height without units.

update: width: 400; -> width: 400px; height: 229; -> height: 229px;

.img-lightning {
  width: 400px;
  height: 229px;
  background-image: url(images/lightning.jpg);
}

CodePudding user response:

Do you get the cracked image? If so - its pulling the data correct but perhaps your link to image is wrong.

Check your directory path especially if your css is in a /css directory. Your call here background-image: url(images/lightning.jpg); is assuming it is in: /css/images

I keep my directories seperate... (main)/css and (main)/images

If that is the case you may need to go back 1 directory. Add? ../

background-image: url(../images/lightning.jpg);

Also just saw... width: 400; height: 229;

Should it be?

width: 400px; height: 229px;

CodePudding user response:

You have forgot to mention property unit

.img-lightning {
  width: 400px;
  height: 229px;
  background-image: url(images/lightning.jpg);
}
  • Related