on website there are multiple .svg files is there a trick to use $primary colour from style.scss instead of using the standard .svg
fill="#2F2F41"
applying $primary to svg fill does not work by default and I wonder if there is an easy trick to apply the primary colour automatically instead of entering manual colour code to each image
Hello @inder
As per my understanding and experience, you can not control SVG colors from scss if you loads svg as image . but you can change the fill color if you add svg as code . Then use this property to add your custom color .
This does not help as the code you provide is a static code and apply to all icons (hero-graphic-name.svg files does not fell under the .icon class )
I just want the desired .svg files to fetch from $primary colour code that I have in style.scss. Instead of writing a static # colour code in each .svg file
this way I can apply $primary colour to graphics directly from style.scss and I can extend the no. of graphics the primary colour applies to.
If you are including the SVG via img-Tag then Hugo can’t help you with this task.
If you are including the SVG inline in the HTML of a layout that is processed by Hugo, then you can define something along the lines of .surroundingclass svg tagname for any tagname inside of the SVG to style it.
SVG files themselfes don’t “fetch” anything from SCSS, as these are unprocessed stylesheets and not available to the SVG file itself, mostly outside of the webroot directory. One is used while creating the website and the other later on, when serving the website.
If you want to CREATE SVG files with hugo, that’s possible via custom output types and in THAT case they might be able to fetch something from the assets directory.
Yes, it is not possible to directly control SVG fill using colour variables in CSS. That sucks, but there is slight workaround. Put SVG inside DIV and define colour for SVG inside div.
Below is an extract on how I am using it on my website.
That’s what we all are saying the whole time If you insert an SVG as image source you CAN NOT CONTROL the styling (other than putting the css INSIDE of your SVG file).
It’s really not a Hugo question. Maybe you can find a solution on Stackoverflow.
there are multiple solutions for .svg fill control I was asking here as Hugo generate html css from what we provide I was wondering if it can also tweak graphics fill: as it export the site based on the primary colour provided in style.scss
I am 90% sure it is not possible in Hugo currently as I search and test alot but again you never know there might be wizard who already discovered a solution
This is how static HTML works. If you write static colour into html file, you cannot expect this to change, unless you use JavaScript or colour is taken from CSS (like in mine example and others).