Figured out how to color text black or white depending on background lightness without breaking the components down to HSL in #css
Edit: this is now a blog post! https://miunau.com/posts/dynamic-text-contrast-in-css/
Quick and dirty filter stackingAssuming --bgColor contains your background color:
span {This will turn to black around #AAAAAA. adjust brightness lower if you want it to turn to black earlier. play around with contrast as well, using low and high values.
After playing around with this (thanks @mia), we noticed there's some fringes happening at certain color values right when it is about to switch from black to white, so this might work best with colors that you get to control to some degree.
Less fringing with SVG filtersBut! Here is a version that has no fringing:
Add this somewhere in your markup- it can be anywhere as long as the id bwFilter can be referenced.
Then just reference it in your css:
span {tada! no fringing!
svg version here: https://codepen.io/miunau/pen/oNVaJoN?editors=1100
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.