docs(tips-and-tricks): improve image theming tips (#1152)

This commit is contained in:
uncenter authored and GitHub committed 2024-08-02 13:03:36 -04:00
1 parent cdd26cc63a
commit 4173b56b63
1 file changed
+7 -4
+7 -4
View File
@@ -72,9 +72,9 @@ The command above is converting the input image `old-image.png` to the output fi
### How do I theme images and SVGs?
#### SVG background images
#### SVGs as `background-image`s
Often, websites will use a CSS rule to apply an SVG as a `background-image` (typically for icons). We will refer to these as "external SVGs" throughout the rest of this guide. Below is an example of what a rule for an external SVG could look like.
Websites will sometimes use the `background-image` CSS property to apply an SVG, often for icons. We will refer to these as "external SVGs" throughout the rest of this guide, as the SVGs are usually at a different URL and linked to with [`url()`](https://developer.mozilla.org/en-US/docs/Web/CSS/url). Below is an example of what a rule for an external SVG could look like.
```css
.xyz {
@@ -91,13 +91,16 @@ The easiest way to theme external SVGs is to visit the URL of the SVG and paste
}
```
> [!NOTE]
> The `Invalid % without number` error may appear if you have not done the following step. Make sure to add/replace an interpolated color in the SVG contents (as is detailed below) for this error to go away.
Now, replace any colors in the SVG with their respective Catppuccin variants. For example, take the following SVG icon for Twitter:
```xml
<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#1D9BF0" d="M21.543 7.104c.015.211.015.423.015.636 0 6.507-4.954 14.01-14.01 14.01v-.003A13.94 13.94 0 0 1 0 19.539a9.88 9.88 0 0 0 7.287-2.041 4.93 4.93 0 0 1-4.6-3.42 4.916 4.916 0 0 0 2.223-.084A4.926 4.926 0 0 1 .96 9.167v-.062a4.887 4.887 0 0 0 2.235.616A4.928 4.928 0 0 1 1.67 3.148 13.98 13.98 0 0 0 11.82 8.292a4.929 4.929 0 0 1 8.39-4.49 9.868 9.868 0 0 0 3.128-1.196 4.941 4.941 0 0 1-2.165 2.724A9.828 9.828 0 0 0 24 4.555a10.019 10.019 0 0 1-2.457 2.549z"/></svg>
```
There is only one color used, `fill="#1D9BF0"`. That hex code is a shade of blue, so we can replace it with the `@blue` color using the `fill="@{<color>}"` syntax.
There is only one color used, `fill="#1D9BF0"`. That hex code is a shade of blue, so we can replace it with the `@blue` color using the `fill="@{<color>}"` syntax ([variable interpolation](https://lesscss.org/features/#variables-feature-variable-interpolation)).
```less
.twitter-icon {
@@ -110,7 +113,7 @@ There is only one color used, `fill="#1D9BF0"`. That hex code is a shade of blue
#### `<img>` elements
Theming an inline image is similar, but we use `content` to cover up the original image with our new one. You only need to update the SVG inside of the `escape('')` and you're all set.
Theming an inline image is similar, but `content` is used instead of `background-image` to cover up the original image with our new one. As with the previous tip for `background-image`, you only need to update the SVG inside of the `escape('')` (see above for details).
```less
img.xyz {