简体   繁体   English

CSS:IMG尽管位于正确的位置,但仍未显示

[英]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. 我无法获得要显示在HTML页面上的图像。 I believe my css links correctly, I also believe my image links correctly. 我相信我的CSS链接正确,我也相信我的图像链接正确。 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. 我不确定这是否是“图像未位于正确的位置”类型的问题,或者我是否只是未正确使用“ background-image:url”。

I just want the image to display on my html page. 我只希望图像显示在我的html页面上。 Please advise. 请指教。

CSS: 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: 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: 您需要将url()更改为:

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. ../表示离开css文件夹, img/表示进入img文件夹, background.jpg表示使用background.jpg图像。

 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"> 您还忘记了</div> <div class="row"></div>关闭标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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