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

How to change the background of an image with css

王林
王林Original
2021-05-21 15:56:175269browse

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>

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!

Statement:
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