Last active
January 7, 2023 03:58
-
-
Save Mix-Liten/3d77f0b63b91fe8db112af69158e41c0 to your computer and use it in GitHub Desktop.
Methods for Contrasting Text Against Backgrounds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
demo
reference: css-tricks's post