"; 2. Add "{background-image:url" to the div element (Picture name);}" style."/> "; 2. Add "{background-image:url" to the div element (Picture name);}" style.">

Home  >  Article  >  Web Front-end  >  How to set div background image in html

How to set div background image in html

WBOY
WBOYOriginal
2021-11-15 11:57:4454803browse

htmlHow to set the div background image: 1. Use the style attribute of the div element, the syntax is "

"; 2. Give the div element Add "{background-image:url(image name);}" style.

How to set div background image in html

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

htmlHow to set a div background image

1. The syntax for adding a background image to a div in html is as follows:

<div style="width:宽度值; height:高度值; background:url(图片名称.jpg);"></div>

Put the pictures and web pages in a folder. Pay attention to the picture suffix. .jpg here is only suitable for JPG pictures. Change the suffix for other types of pictures by yourself.

The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo</title>
</head>
<body>
<div style="width: 200px;height: 100px;background: url(1115.08.png);"></div>
</body>
</html>

Output result:

How to set div background image in html

2. You can add "{background-image:url( Picture name);}" style to set the background image, the code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>demo</title>
<style>
.ellipse{
width: 400px;
height: 200px;
background-image: url(1115.08.png);
}
</style>
</head>
<body>
<div class="ellipse"></div>
</body>
</html>

Output result:

How to set div background image in html

For more programming-related knowledge, please visit: programming video! !

The above is the detailed content of How to set div background image in html. 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