我如何在css中的文件夹中添加背景图片? [英] how do i add an image in the background in css from a folder?
问题描述
我有一张图片,根据我在W3school中看到的,您可以使用
body background = farm.jpg
这个方法很有效,但是它说,我也看到有人这样说,它可以在css中使用
background- image:url(farm.jpg)
(带和不带引号)
然而每当我尝试它时都找不到图片。需要把它放在一个单独的文件夹中?
(1) https://www.w3schools.com/tags/att_body_background.asp
非幸运HTML5不支持背景属性。您可以使用CSS代替。
(2)您可以使用此页面的代码示例, p> https://wiki.selfhtml.org/wiki/ CSS / Eigenschaften / Hintergrundfarben_und_-bilder / background-image
例如:
<!doctype html>
< html lang =en>
< head>
< meta charset =utf-8>
< title>您的网页< / title>
< meta name =descriptioncontent =The HTML5 page>
< meta name =authorcontent =Your Name>
< link rel =stylesheethref =css / styles.css?v = 1.0>
< style>
body {
background-image:url(background.png);
}
< / style>
< / head>
< body>
< p>测试。< / p>
< / body>
< / html>
希望这有助于您。
I have an image, and from what I've seen in W3schools you can just use
body background = farm.jpg
And that works, but it says and I've seen people say this, that it can work with css with
background-image: url(farm.jpg)
(with and without quotes)
yet whenever i try it can't find the picture.Do I need to put it in a separate folder?
(1) https://www.w3schools.com/tags/att_body_background.asp
Unfourtunately the background attribute is not supported in HTML5. You must use CSS instead.
(2) You can use the code example form this page, what works:
https://wiki.selfhtml.org/wiki/CSS/Eigenschaften/Hintergrundfarben_und_-bilder/background-image
For example:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Your page</title>
<meta name="description" content="The HTML5 page">
<meta name="author" content="Your Name">
<link rel="stylesheet" href="css/styles.css?v=1.0">
<style>
body {
background-image: url("background.png");
}
</style>
</head>
<body>
<p>Test.</p>
</body>
</html>
Hope this helps.
这篇关于我如何在css中的文件夹中添加背景图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!