I run a blog where I wanted to create a subsite showcasing my favorite apps. To maintain code consistency and avoid confusion with the existing HTML code that describes the website, I decided to create a separate "subHTML" specifically for app cards.
So far, the best I've been able to do with this code is display the texted source of the image instead of the actual image. I have tried various CSS solutions such as using content: attr(data-src url)
, experimenting with different parameters inside var()
, attempting
background-image: attr(data-src url)
, adjusting max-width
, max-height
, width
, height
properties, utilizing ::before
, etc.
Here is the current non-working code:
:root{
--icon: attr(data-src);
}
app-icon::before{
display: inline-block;
content: var(--icon);
}
<app-box><app-title>app name</app-title><app-icon data-src="https://live.staticflickr.com/2552/3794648454_cf0c2a228b_b.jpg"></app-icon></app-box>
Few additional notes:
- I prefer not to use JavaScript for accessibility reasons
- I also try to avoid using JavaScript to prevent confusion
- I have sought help in other places but haven't found a solution yet
- I am familiar with XML and would like to use it in other projects as well
- I am using Firefox, but friends with other browsers also encounter the same issue (so it's not a browser-specific bug)
- I understand that custom tags usually don't have defined attributes except for id and class, so I created custom ones
- I am aware of the default CSS property of
inline-block
for the img tag
Screenshot of the current bug :
https://i.sstatic.net/NTbkl.png
This blog can be accessed at : if anyone wants to test this buggy CSS themselves
If anyone knows how to successfully display an image from a custom tag, please share your insights!