简体   繁体   中英

CSS: IMG not displaying despite being located in the right place

I cannot get the image I want to be displayed on my HTML page. I believe my css links correctly, I also believe my image links correctly. I am unsure if this is a "image not located in the right place" type of issue, or if I am simply not using "background-image: url" correctly.

I just want the image to display on my html page. Please advise.

CSS:

 {
      margin: 0;
      padding: 0;

    }

    header{

    /* why won't this work? */
      background-image: url(img\background.jpg);

      height: 100vh;
      background-size: cover;
      background-position: center;

    }

    /* header {
        background-color: linen;
    } */

    h1 {
        color: maroon;
        margin-left: 40px;
    }

Directory structure: 在此处输入图片说明 HTML:

<!DOCTYPE html>
<html>

  <head>
<!-- I have no idea what these do -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Kacie Ahmed</title>

    <!-- Link to my stylesheet -->
    <link href="css/webpage.css" rel="stylesheet" type="text/css">

</head>


  <body>

    <header>

      <div class="row">
        <ul class="main-nav">
          <li> <a href=""> HOME</li>
            <li> <a href=""> ABOUT ME</li>
              <li> <a href="">EXPERIENCE</li>
                <li> <a href="">SKILLS</li>

        </ul>


    </header>

  </body>

</html>

Your directory is incorrect. You need to change your url() to be:

background-image: url('../img/background.jpg');

The ../ means go out of the css folder, the img/ means go into the img folder, and the background.jpg means use the background.jpg image.

 header{
    background-image: url('../img/background.jpg');;
    height: 100vh;
    background-size: cover;
    background-position: center;
 }

Also, note that you should use forward slashes ( / ) rather than backslashes ( \\ ) and your url should be wrapped within quotes (as a string)

The Url of your image is not correct, use / instead of \\ .

You also forgot the </div> close tag for the <div class="row">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM