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 👍
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it
Online Users
Forgot your key, lost your files, need a previous Lay Theme or Addon version?
Go to www.laykeymanager.com