javascript - 在 175 度 50% 高度后更改文本颜色

标签 javascript css css-transitions

我在 50% 高度后以 175 度 Angular 更改背景颜色。因此,当背景颜色为蓝色时,我希望文本颜色变为白色。 Fiddle

.bg {
      background: linear-gradient(175deg, #e2e2e2 50%, #435289 50%);
      color:#000;
}
<div class="bg">
<h1>
 Hiii, My Name is John, I love Stackoverflow. I really don't know, how to do this, Can someone help me? If Background = Blue, Text Color = White
</h1>
  
</div>


</div>

最佳答案

新答案:

使用相同形状的线性渐变设置 h1 元素的背景,但文本的颜色是您想要的。将文本颜色设为透明,然后使用 background-clip: text(注意 browser's compatibility )为文本着色。

.bg {
  background: linear-gradient(175deg, #e2e2e2 50%, #435289 50%);
  color: #000;
}

h1 {
  color: transparent;
  background: linear-gradient(175deg, #435289 50%, white 50%);
  -webkit-background-clip: text;
  background-clip: text;
}
<div class="bg">
  <h1>
    Hiii, My Name is John, I love Stackoverflow. I really don't know, how to do this, Can someone help me? If Background = Blue, Text Color = White
  </h1>

</div>


</div>

原答案:

如果你需要对比度,而不是精确的颜色,你可以使用 mix-blend-mode根据背景动态改变颜色:

.bg {
  background: linear-gradient(175deg, #e2e2e2 50%, #435289 50%);
  color: #000;
}

h1 {
  color: #fff;
  mix-blend-mode: difference;
}
<div class="bg">
  <h1>
    Hiii, My Name is John, I love Stackoverflow. I really don't know, how to do this, Can someone help me? If Background = Blue, Text Color = White
  </h1>

</div>


</div>

关于javascript - 在 175 度 50% 高度后更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44522300/

相关文章:

javascript - 对包含数组的数组进行排序

javascript - 单击时定位数组中的项目?

javascript - Highcharts 条形数据标签位置

jquery - 如何在点击/加载时滑入新加载的图像

html - 如何转换 z-index?

当鼠标提前离开元素时,CSS 过渡步骤失败

javascript - 打开新选项卡,但应用作带有已保存搜索的后退按钮

javascript - 有没有办法使用 Discord.js 回复机器人来激活命令。另外,给用户一定的时间来使用该命令

html - 选择标签显示不正确

php - 如何使用 PHP 路由和 .htaccess 包含 CSS/JS 和其他文件