I use Tailwind for one of my sites. I want to place the cover image as a background image, but somehow it is not detected by Tailwind styles. Here’s how I am doing it (with a main image and fallback image)
{{- with or (.Resources.GetMatch "featured.jpg") (resources.Get "fallback.jpg") }}
<div class="w-full bg-cover bg-center bg-no-repeat bg-[linear-gradient(rgba(0,0,0,0.4),rgba(0,0,0,0.5)),url({{ .RelPermalink }})]">
{{ end }}
Adding resources.ExecuteAsTemplate "style.css" . to the stylesheet in the header does not work either. But defining the image and its styles inline with styles="" works
I do something similar to this — also for the sake of the CSP — in some of my image-handling shortcodes, such as hugo_site/imgh.html at main · brycewray/hugo_site · GitHub. The code adds a new, uniquely named* class on the fly and then assigns it to the image’s div. Perhaps you can adapt this approach to what you’re wanting to do.
* The name comes from applying md5 to the image file name, as you’ll see by looking earlier in the code than that line-specific URL above.