Skip to content

Instantly share code, notes, and snippets.

@Mix-Liten
Last active January 7, 2023 03:58
Show Gist options
  • Save Mix-Liten/3d77f0b63b91fe8db112af69158e41c0 to your computer and use it in GitHub Desktop.
Save Mix-Liten/3d77f0b63b91fe8db112af69158e41c0 to your computer and use it in GitHub Desktop.
Methods for Contrasting Text Against Backgrounds
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
html,
body {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: system-ui;
}
body {
width: 100%;
display: flex;
justify-content: center;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
margin-top: 24px;
}
.box {
width: 200px;
height: 50px;
display: flex;
align-items: center;
justify-content: center;
background-color: #000;
border: 1px solid;
border-radius: 10px;
}
/* .txt {
color: #fff;
mix-blend-mode: difference;
} */
.txt {
background: inherit;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
font-size: 24px;
filter: invert(1) grayscale(1) contrast(9);
}
</style>
</head>
<body>
<div class="container">
<div class="box" style="background-color: #ff158a;"><h3 class="txt">Text</h3></div>
<div class="box" style="background-color: #ffffff;"><h3 class="txt">Text</h3></div>
<div class="box" style="background-color: #4eccc6;"><h3 class="txt">Done</h3></div>
<div class="box" style="background-color: #175a63;"><h3 class="txt">In Progess</h3></div>
<div class="box" style="background-color: #b5bcc2;"><h3 class="txt">Stuck</h3></div>
<div class="box" style="background-color: #000000;"><h3 class="txt">Text</h3></div>
</div>
</body>
</html>
@Mix-Liten
Copy link
Author

Mix-Liten commented Jan 7, 2023

demo

reference: css-tricks's post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment