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


body{
background:url("?../img/by.jpg") no-repeat;
background-size:cover;

}

这个代码能在所有浏览器中工作吗或者我可以在没有问号的情况下完成它???

尝试一下,它将在所有浏览器上运行。

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>

使用此功能将图像背景设置为元素,这也适用于所有浏览器

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

最新更新