使用css添加背景图片的代码正确吗?

yxyvkwin  于 2023-02-26  发布在  其他
关注(0)|答案(2)|浏览(175)
body{
background:url("?../img/by.jpg") no-repeat;
background-size:cover;

}
这段代码可以在所有浏览器中工作吗?或者我可以不带问号?

emeijp43

emeijp431#

试试这个,它会在所有的浏览器上工作。

body{
/*
background: color-name url("image-source") repeat-property attachment-property position-property;
Shorthand Example :- */
background: #D0E4F5 url("https://picsum.photos/200") no-repeat scroll 0px 0px;
/*
Long Example :-
#demo {
background-color: #D0E4F5;
background-image: url("/images/smiley.png");
background-repeat: no-repeat;
background-attachment: scroll;
background-position: 0px 0px;
}
*/

}
<html>
<head></head>
<body>
Some Example Text
</body>
</html>
disbfnqx

disbfnqx2#

使用这个来背景图像的一个元素,这也将工作在所有浏览器

element {
  background-image: url('your_Source');
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}

相关问题