如何使用Thymeleaf构建srcset属性

问题描述 投票:0回答:2

使用标准网址语法srcset使用Thymeleaf构建@{/...}属性的正确方法是什么?

例:

<img th:src="@{/i/1000.jpg}" srcset="/i/1500.jpg 1500w, /i/2000.jpg 2000w" />
java thymeleaf template-engine
2个回答
2
投票

没关系,它比预期更容易和同时合乎逻辑:

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

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" />
© www.soinside.com 2019 - 2024. All rights reserved.