Home >Web Front-end >Front-end Q&A >How to insert pictures in Css
How to insert pictures using Css: first create an HTML sample file; then create a div in the body; finally insert pictures by setting the "background-image: url(1.jpg);" style.
The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.
In css, you can use the background-image attribute to add pictures. The background-image property sets the background image for the element. The initial background image (original image) is placed according to the value of the background-position property. The background of an
element occupies the entire 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 horizontally and vertically.
Tip: Please set an available background color so that the page can get good visual effects even if the background image is not available.
Details
The background-image attribute sets an image in the background of the element. Depending on the value of the background-repeat property, the image can be tiled infinitely, tiled along some axis (x- or y-axis), or not tiled at all.
The initial background image (original image) is placed according to the value of the background-position attribute.
Attribute value:
url('URL') Path pointing to the image.
none Default value. No background image is displayed.
[Recommended learning: css video tutorial]
Example:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style type="text/css"> div{ width: 400px; height: 300px; border: 1px solid red; } .img1{ background-image: url(1.jpg); background-size: 200px; } </style> </head> <body> <div class="img1"></div> </body> </html>
Rendering:
The above is the detailed content of How to insert pictures in Css. For more information, please follow other related articles on the PHP Chinese website!