Set Webpage Background Image with CSS
One common method to add an image to a webpage background is to use CSS styles.
- Add the following style code to the CSS file:
body {
background-image: url('path/to/your/image.jpg');
background-size: cover; /* 图片会被拉伸或压缩以适应整个屏幕 */
background-position: center; /* 图片位置居中 */
background-repeat: no-repeat; /* 不重复显示图片 */
}
- Replace ‘path/to/your/image.jpg’ in the above code with the path to the image you want to set as the background.
- Link the CSS file to your HTML file to ensure that the styles are applied correctly.
- Refresh your webpage and you should be able to see the background has been added, with the image displayed on the background of the page.
Remember to choose high-resolution images to ensure they display clearly on screens of different sizes and resolutions.