gpt4 book ai didi

javascript - 根据背景更改固定位置div的背景和字体颜色

转载 作者:行者123 更新时间:2023-12-02 21:21:29 25 4
gpt4 key购买 nike

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="background1">Div1</div>
<div class="background2">Div2</div>
<div class="background3">Div3</div>
<div class="background4">Div4</div>
<div class="fixed-background">This should change color based on background</div>

</body>
</html>




div {
height: 100vh;
}

.background1 {
background: gray;
}

.background2 {
background: black;
}

.background3 {
background: blue;
}

.background4 {
background: tomato;
}

.fixed-background {
position: fixed;
top: 10px;
left: 10px;
width: 100px;
height: 100px;
mix-blend-mode: difference;
}

大家好,我尝试根据另一个div的背景使用fixed-background类来更改div的背景和颜色。我遇到了 mix-blend-mode CSS 属性,但它似乎不起作用。

我到目前为止还不是 CSS 专家,有人可以帮助我让它工作吗?如果我让它与 JS 函数一起工作,我不会不高兴。

最佳答案

我一直在尝试mix-blend-mode,也许我已经得到了你需要的东西。请检查一下。重要的是您必须检查浏览器的兼容性。

https://developer.mozilla.org/en-US/docs/Web/CSS/mix-blend-mode

body {
margin-bottom: 50vh;
}

.background1,
.background2,
.background3,
.background4 {
height: 50vh;
}

.background1 {
background: gray;
}

.background2 {
background: black;
}

.background3 {
background: blue;
}

.background4 {
background: tomato;
}

.fixed {
position: fixed;
top: 10px;
right: 10px;
width: 100px;
height: 100px;
mix-blend-mode: screen;
}

.fixed-text {
background: green;
color: maroon;
mix-blend-mode: difference;
z-index: 3;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
<div class="background1">Div1</div>
<div class="background2">Div2</div>
<div class="background3">Div3</div>
<div class="background4">Div4</div>
<div class="fixed">
<div class="fixed-text">
This should change color based on background
</div>
</div>

关于javascript - 根据背景更改固定位置div的背景和字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60834601/

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