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.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>Copy after loginPut 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>Copy after loginOutput result:
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>Copy after loginOutput result:
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!