View Single Post
Old 12-05-2024, 12:32 PM   #8
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,355
Karma: 20171571
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
Hi all!

After playing around a bit I thought I'd post my results in case anyone else was interested.
I built this using ePub2. If you are creating an ePub3 only book then you could possibly use javascript. The device/app would also need to support some specific css...so, definitely test on your device...

Using fill:currentcolor and stroke:currentcolor in your css works but only under certain circumstances.
In an ePub you could embed the svg code directly in the html page:
Code:
svg path, svg stroke {fill:currentcolor; stroke:currentcolor}

<p>yadda yadda</p>
<svg><g><path d="......"/></g></svg>
<p>yadda yadda</p>
Unfortunately, the last I heard, some readers/apps (kindle) don't support embedded svg very well. They want you to wrap the svg in an <img> tag (<img alt="" src="img.svg"/>). The value for currentcolor wont translate into the <img> tag. Also, embedding all that svg code can get a bit clunky, especially if you are using it a lot.

After practicing a bit more google-fu I found that you could use image masks in your css and simply set the backgound-color to currentcolor. Image masks are almost universally supported in browsers (except IE...go figure...), so there is a decent chance they will work on your device/app as well! The downside is that you are limited to fairly simple, monochrome style, images...but since these are used for scene breaks, and we're mostly worried about a dark image on a dark background, that's not too bad.

Code:
hr {border:none; margin:1.5em auto; text-align:center; overflow: hidden;
    page-break-inside: avoid; break-inside: avoid} 
    //*This is just the defaults I use for an hr...style yours however you wish *//

hr.ChDiv {
    height:.3em;
    background-color:currentcolor;
    -webkit-mask-image: url('../Images/img_ChDiv.svg');
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-size: auto 100%;
    -webkit-mask-position: center;

//* if your device doesn't support webkit, 
    then you could try the non-webkit version *//
    mask-image: url('../Images/img_ChDiv.svg');
    mask-repeat: no-repeat;
    mask-size: auto 100%;
    mask-position: center;
}
You will just need to set the height and mask-size to the proper size.

Here are a few screenshot examples:
Click image for larger version

Name:	Screenshot 2024-12-05 113830.png
Views:	318
Size:	231.5 KB
ID:	212356 Click image for larger version

Name:	Screenshot 2024-12-05 113906.png
Views:	339
Size:	235.5 KB
ID:	212357 Click image for larger version

Name:	Screenshot 2024-12-05 113944.png
Views:	323
Size:	245.4 KB
ID:	212358

Also, this technique is not limited to svg...it works fine with .png and .jpg...just remember it is using a mask, so none of the image detail will be visible, just a silhouette. Here are some screenshots with a .png
Code:
-webkit-mask-image: url('../Images/img_ChDiv.png')
        mask-image: url('../Images/img_ChDiv.png')
Click image for larger version

Name:	Screenshot 2024-12-05 122653.png
Views:	319
Size:	126.0 KB
ID:	212359 Click image for larger version

Name:	Screenshot 2024-12-05 122637.png
Views:	337
Size:	137.5 KB
ID:	212360

Hope that helps someone!

Cheers!


edit: it works with .jpg but jpg normally doesn't have a transparency channel, so it will just show up as a silhouette of the entire picture including the background. ie it will just be a solid rectangle...

edit: edit: you don't have to specify the mask-size separately...you can just leave it as mask-size: auto 100%; then you only need to change the height.

Last edited by Turtle91; 12-05-2024 at 08:15 PM.
Turtle91 is offline   Reply With Quote