+
80
-

css如何让文字颜色智能适配背景?

css如何让文字颜色智能适配背景?

比如背景是深色,那么文字就是白色,如何背景是白色,那么文字就是深色。


网友回复

+
0
-

mix-blend-mode:设为difference即可,看看效果:

800_auto

代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum=1.0,minimum=1.0,user-scalable=0" />
    <title>BFW NEW PAGE</title>

     <style>
     body{
         padding: 0;
         margin: 0;
     }
     .banner{
         background: url("//repo.bfw.wiki/bfwrepo/image/65422df611d69.png");
         background-repeat: no-repeat;
         background-size: cover;
         height: 100vh;
     }
     .title {
font-size:100px;
text-align: center;
line-height: 100vh;
color:white;
margin: 0 auto;
mix-blend-mode: difference;

}
      </style>
</head>
<body>
    <div class="banner">
       <h1 class="title">我是标题</h1>
    </div>
</body>
</html>
		

我知道答案,我要回答