white typeface on dark background
-
Hello I am trying to make my typeface color turn white on dark backgrounds and black on lighter backgrounds. any ideas? :-)
so far i've used this :
function hexToRgb(hex) {
const hexCode = hex.charAt(0) === '#'
? hex.substr(1, 6)
: hex;const hexR = parseInt(hexCode.substr(0, 2), 16); const hexG = parseInt(hexCode.substr(2, 2), 16); const hexB = parseInt(hexCode.substr(4, 2), 16); // Gets the average value of the colors const contrastRatio = (hexR + hexG + hexB) / (255 * 3); return contrastRatio >= 0.5 ? 'black' : 'white';}
-
Dear @giselach
These Links may help:
https://css-tricks.com/switch-font-color-for-different-backgrounds-with-css/
https://css-tricks.com/methods-contrasting-text-backgrounds/
Best
Richard
-
maybe this:
.div{ color: white; mix-blend-mode: difference; } -
Thanks @felix_rabe 👍
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login