How to insert pictures in Css

藏色散人
Release: 2023-01-05 16:11:06
Original
99749 people have browsed it

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.

How to insert pictures in Css

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>
Copy after login

Rendering:

How to insert pictures in Css

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!

Related labels:
css
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