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

后端 未结 25 2194
借酒劲吻你
借酒劲吻你 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:19

    Or you could do this which I found on the interweb thingy.

    https://robau.wordpress.com/2012/04/20/override-image-src-in-css/

    
    
    .egg {
      width: 100%;
      height: 0;
      padding: 0 0 200px 0;
      background-image: url(linkToImage.jpg);
      background-size: cover;
    }
    

    So effectively hiding the image and padding down the background. Oh what a hack but if you want an IMG tag with alt text and a background that can scale without using JavaScript?

    In a project I'm working on now I created a hero block twig template

    {{ altText }}

提交回复
热议问题