The src attribute of img can be written in css; the src attribute is used to set the url of the image file in the img tag, that is, the file path of the image. You can use the content attribute of css to specify the image url of the img tag. , you can achieve the purpose of using css to set the src attribute of the img tag. The syntax is "img{content:url(image file path);}".
The operating environment of this tutorial: Windows 10 system, CSS3&&HTML5 version, Dell G3 computer.
The src attribute of the tag is required. Its value is the URL of the image file, which is the absolute or relative path to the file that references the image.
Tip: In order to organize the storage of documents, creators usually store image files in a separate folder, and usually name these directories something like "pics" or "images". In the W3School online tutorial, our engineers store most of the commonly used images in a folder named "i". "i" is the abbreviation of "images". The advantage of this is that it can simplify the path to the greatest extent. .
Syntax
<img src="value" alt="Can the src attribute of img be written in css?" >
URL
Specifies the URL of the image.
Possible values:
Absolute URL - points to another site (such as src="http://www.example.com/")
Relative URL - points to the site The
content attribute is used with the :before and :after pseudo-elements to insert content.
The possible attribute values of this attribute are as follows:
The example is as follows:
<style> img { content:url(https://image.png); } </style>
(Learning video sharing: css video tutorial、html video tutorial)
The above is the detailed content of Can the src attribute of img be written in css?. For more information, please follow other related articles on the PHP Chinese website!