【问题标题】:How to build srcset attribute with Thymeleaf如何使用 Thymeleaf 构建 srcset 属性
【发布时间】:2017-11-23 13:05:32
【问题描述】:

使用标准 url 语法 @{/...} 构建带有 Thymeleafsrcset 属性的正确方法是什么?

例子:

<img th:src="@{/i/1000.jpg}" srcset="/i/1500.jpg 1500w, /i/2000.jpg 2000w" />

【问题讨论】:

    标签: thymeleaf template-engine


    【解决方案1】:

    在thymeleaf中构建srcset属性的正确方法如下:

    <img th:attr="srcset=|@{/img/image1x.png} 1x, @{/img/image2x.png} 2x, @{/img/image3x.png} 3x|" th:src="@{/img/image1x.png}" alt="My image description text" />
    

    【讨论】:

      【解决方案2】:

      没关系,这比预期的要容易且合乎逻辑:

      <img
          th:src="@{/i/1000.jpg}"
          th:attr="srcset=@{/i/1500.jpg} + ' 1500w, ' + @{/i/2000.jpg} + ' 2000w'"
      />
      

      【讨论】:

        猜你喜欢
        • 2021-10-13
        • 1970-01-01
        • 1970-01-01
        • 2018-09-02
        • 1970-01-01
        • 1970-01-01
        • 2013-01-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多