Is it possible to set the equivalent of a src attribute of an img tag in CSS?

后端 未结 25 2738
借酒劲吻你
借酒劲吻你 2020-11-22 09:30

Is it possible to set the src attribute value in CSS? At present, what I am doing is:


25条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 10:02

    Here is a very good solution -> http://css-tricks.com/replace-the-image-in-an-img-with-css/

    Pro(s) and Con(s):
    (+) works with vector image that have relative width/height (a thing that RobAu's answer does not handle)
    (+) is cross browser (works also for IE8+)
    (+) it only uses CSS. So no need to modify the img src (or if you do not have access/do not want to change the already existing img src attribute).
    (-) sorry, it does use the background css attribute :)

提交回复
热议问题