Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. Need Custom Coding for Lay Theme? Find 3rd Party Developers here.
  3. white typeface on dark background

white typeface on dark background

Scheduled Pinned Locked Moved Need Custom Coding for Lay Theme? Find 3rd Party Developers here.
4 Posts 3 Posters 119 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    giselach
    wrote on Apr 16, 2022, 1:18 PM last edited by giselach Apr 16, 2022, 9:39 AM
    #1

    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';
    

    }

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Richard
      Global Moderator
      wrote on May 8, 2022, 9:09 PM last edited by
      #2

      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
      1 Reply Last reply
      0
      • F Offline
        F Offline
        felix_rabe
        wrote on May 21, 2022, 2:49 PM last edited by
        #3

        maybe this:

            .div{
                   color: white;
                   mix-blend-mode: difference;
            }
        
        1 Reply Last reply
        0
        • R Offline
          R Offline
          Richard
          Global Moderator
          wrote on May 22, 2022, 9:08 PM last edited by
          #4

          Thanks @felix_rabe 👍

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          I also code custom websites or custom Lay features.
          💿 Email me here: 💿
          info@laytheme.com

          Before you post:
          1. When using a WordPress Cache plugin, disable it or clear your cache.
          2. Update Lay Theme and all Lay Theme Addons
          3. Disable all Plugins
          4. 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:
          1. Post a link to where the problem is
          2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
          3. If the problem is difficult to explain, post screenshots / link to a video to explain it
          Online Users
          C
          craigfeldspar
          6 minutes ago
          Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
          laytheme.com
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • Users
          • Search