CSS - 仅显示左上角的图像背景



我试图将此图像作为背景,但是当我使用此代码时:

<body style="background-image: url('./image.jpg');">......仅显示左上角的部分。

您可以使用:

background-size: cover; 

您可以在此处找到有关背景大小属性的文档:

尝试以下背景属性

body {
background-image: url('./image.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

使用background-size样式修改背景图像的大小和在父图像中的位置。MDN 文档。

body {
background: url('https://i.stack.imgur.com/n3OMH.jpg') no-repeat;
background-size: cover;
}

试试这个:

background-size: 100% 100%; /*first value is for width and next for height. If you use only first of them, it will be used as width, and height will be auto*/

background-size: cover;

最新更新