Home > Web Front-end > CSS Tutorial > How to change the background of an image with css

How to change the background of an image with css

王林
Release: 2023-01-06 11:14:57
Original
5303 people have browsed it

The way to change the background of an image in css is to add the background-image attribute and set the attribute value to the URL address of the image you want, for example [background-image:url('../images/ mix/paper.gif');].

How to change the background of an image with css

The operating environment of this article: windows10 system, css 3, thinkpad t480 computer.

The background-image property sets the background image of an element. The background of an element is the total size of the element, including padding and borders (but not margins).

By default, the background-image is placed in the upper left corner of the element and repeats vertically and horizontally.

Common attribute values:

  • url('URL') URL of the image

  • none No image background will be displayed. This is the default

  • inherit Specifies that the background image should be inherited from the parent element

A simple code example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style>
body 
{
	background-image:url(&#39;../images/mix/paper.gif&#39;);
	background-color:#cccccc;
}
</style>
</head>

<body>
<h1>Hello World!</h1>
</body>

</html>
Copy after login

Related video sharing: css video tutorial

The above is the detailed content of How to change the background of an image with css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template