如何在 HTML 中指定在不同情况下使用的图片 URL?
htmlweb developmentfront end technology更新于 2025/8/16 17:48:17
使用 srcset 属性指定在不同情况下使用的图片 URL。
示例
您可以尝试运行以下代码来实现 srcset 属性。调整浏览器大小以查看不同的图片加载情况 −
<!DOCTYPE html> <html> <head> <meta name = "viewport" content="width=device-width, initial-scale = 1.0"> </head> <body> <picture> <source media = "(min-width: 550px)" srcset = "https://www.cainiaomax.com/assets/videotutorials/courses/3d_animation_online_training/380_course_211_image.jpg"> <source media = "(min-width: 400px)" srcset = "https://www.cainiaomax.com/assets/videotutorials/courses/html_online_training/380_course_216_image.jpg"> <img src = "https://www.cainiaomax.com/videotutorials/images/tutorial_library_home.jpg" alt = "Tutorials Library" style = "width:auto;"> </picture> </body> </html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

