简体   繁体   English

CSS初学者,背景图片不会显示

[英]CSS beginner, background image won't show up

My background-image won't show up. 我的背景图片不会显示。 Do I need to tag the image in the HTML? 是否需要在HTML中标记图像? Maybe position reference or something? 也许是职位参考或其他? Please help! 请帮忙!

<html>
<head>
    <link type="text/css" rel="stylesheet" href="sespe.css"/>
    <title>Sespe Pizza Co.</title>
</head>
<body>
    <div id="header1">
        <h1>Sespe Pizza Co.</h1>
    </div>
    <div id="mb1"></div>
    <div id="mb2"></div>
    <div id="mb3"></div>
    <div id="mainPage">

    <div id="b1"></div>
    <div id="b2"></div>
    <div id="b3"></div>
    <div id="b4"></div>
    <div id="b5"></div>
</body>
</html>

CSS..... CSS .....

body {
    background-image:         url('/Users/Username/Downloads/3634195609_f6b7edac1b_b.jpg'); 
}

Your path is the problem. 你的道路是问题。 You are navigating to your downloads folder. 您正在导航到下载文件夹。 Place your image in a folder in your site folder, call it say 'images' and then call it into your css like this. 将您的图像放在站点文件夹中的文件夹中,称其为“ images”,然后像这样将其称为您的CSS。 If your new 'images' folder is on the same level as your css folder, the first option would work. 如果新的“ images”文件夹与css文件夹处于同一级别,则第一个选项将起作用。 ../ because you are going up one folder to get to images . ../因为您要向上一个文件夹来获取images

body {
  background-image: url('../images/3634195609_f6b7edac1b_b.jpg');
}

Edit: Seems in your case, your css file is not in a css folder, so you can just get to your images folder without going to a different level: 编辑:在您的情况下,您的css文件似乎不在css文件夹中,因此您可以直接进入图像文件夹而无需进入另一个级别:

body {
  background-image: url('images/3634195609_f6b7edac1b_b.jpg');
}

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

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