Home >Web Front-end >CSS Tutorial >Can CSS Change an Image's Source Attribute Directly?
Can CSS Alter Image Source Attributes?
Question: Is it possible to modify the src attribute of an img tag using CSS, without employing background or background-image properties?
Solution:
You can achieve this with the content:url() property.
Usage:
.imageClass { content: url("path/to/image.jpg"); }
<img class="imageClass">
Example:
<!DOCTYPE html> <style> .MyClass { content: url("http://imgur.com/SZ8Cm.jpg"); } </style> <img class="MyClass">
The above is the detailed content of Can CSS Change an Image's Source Attribute Directly?. For more information, please follow other related articles on the PHP Chinese website!