gpt4 book ai didi

jquery - CSS - 根据背景更改文本颜色

转载 作者:太空宇宙 更新时间:2023-11-04 14:26:11 25 4
gpt4 key购买 nike

我有一个简单的布局,由三个全高 div 和一个固定的标题栏组成。

body,html {
padding:0;
margin:0;
}

.header {
position:fixed;
width:100%;
height:50px;
color:white;
margin:20px;
}

.section1 {
background:black;
height:100vh;
display: flex;
align-items: center;
justify-content: center;
color:white;
}

.section2 {
background:white;
height:100vh;
display: flex;
align-items: center;
justify-content: center;
}

.section3 {
background:black;
height:100vh;
display: flex;
align-items: center;
justify-content: center;
color:white;
}
<div class="header">
Header Content
</div>
<div class="wrapper">
<div class="section1">
Section One Content
</div>
<div class="section2">
Section Two Content
</div>
<div class="section3">
Section Three Content
</div>
</div>

我试图在标题栏文本滚动到具有白色背景的部分时将其颜色更改为黑色。

我见过几个 jQuery 插件应该可以实现这一点,但我正在努力避免任何不必要的脚本。

CSS mix-blend-mode 函数能让我实现这个吗?有没有人可以举出一个例子来告诉我实现了类似的目标?

最佳答案

您可以使用 mix-blend-mode:difference

body,
html {
padding: 0;
margin: 0;
}

.header {
position: fixed;
width: 100%;
height: 50px;
margin: 20px;
color:#fff;
mix-blend-mode: difference;
}

.section1,
.section2,
.section3{
background: black;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
color: white;
}

.section2 {
background: white;
color:#000;
}
<div class="header">
Header Content
</div>
<div class="wrapper">
<div class="section1">
Section One Content
</div>
<div class="section2">
Section Two Content
</div>
<div class="section3">
Section Three Content
</div>
</div>

关于jquery - CSS - 根据背景更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51630574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com