简体   繁体   English

CSS-背景图片未显示

[英]CSS - Background image doesn't show up

I'm trying to add a background image to my page but it doesn't show up. 我正在尝试将背景图像添加到我的页面,但它没有显示。 Could someone help me out please ? 有人可以帮我吗?

.body{
background-image: url('file:///C:\Users\kaspe\Desktop\Website\backgrund.jpg');}

You are referencing the 'body' HTML tag so you don't need the dot '.'. 您正在引用“正文” HTML标记,因此不需要点“。”。

The dot is used for CSS classes. 该点用于CSS类。

Try: 尝试:

body {
    background-image: url('file:///C:\Users\kaspe\Desktop\Website\backgrund.jpg');
}

You dont need to give it a full path. 您不需要给它一个完整的路径。 just give the foldername/imagename. 只需提供文件夹名称/图像名称。 I assume website is your folder name where you put your image. 我假设网站是您放置图片的文件夹名称。 Try to put it not instead of your code. 尝试放置它而不是您的代码。 Moreover add background-size: cover; 此外,添加背景尺寸:封面; to show image with full screen. 全屏显示图像。

body {
    background-image: url('Website/backgrund.jpg');
    background-size: cover;
}

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

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