相关疑难解决方法(0)

如何仅使用CSS过滤器将黑色转换为任何给定的颜色

我的问题是:给定目标RGB颜色,#000使用CSS滤镜将黑色()重新着色为该颜色的公式是什么?

为了接受答案,它需要提供一个函数(以任何语言)接受目标颜色作为参数并返回相应的CSS filter字符串.

对此的上下文是需要在a内重新着色SVG background-image.在这种情况下,它是支持KaTeX中的某些TeX数学特性:https: //github.com/Khan/KaTeX/issues/587.

如果目标颜色为#ffff00(黄色),则一个正确的解决方案是:

filter: invert(100%) sepia() saturate(10000%) hue-rotate(0deg)
Run Code Online (Sandbox Code Playgroud)

(演示)

非目标

  • 动画.
  • 非CSS过滤器解决方案.
  • 从黑色以外的颜色开始.
  • 关心黑色以外的颜色会发生什么.

结果到目前为止

  • 强力搜索固定过滤器列表的参数:https
    ://stackoverflow.com/a/43959856/181228缺点:效率低下,只生成一些16,777,216种可能的颜色(676,248 hueRotateStep=1).

  • 使用SPSA的更快的搜索解决方案:https : //stackoverflow.com/a/43960991/181228 Bounty奖励

  • 一个drop-shadow解决方案: /sf/answers/3077189741/
    缺点:不上边缘运行.需要非filterCSS更改和次要HTML更改.

您仍然可以通过提交非暴力解决方案获得接受的答案!

资源

javascript css math algebra css-filters

91
推荐指数
6
解决办法
1万
查看次数

更改 SVG 背景图像的颜色(Bootstrap 4 carousel)

我有一个带有下一个/上一个控件的 BS 4 旋转木马,目前可以使用。我有一个浅色背景,所以我想更改控件的颜色(当前为白色)。

HTML:

<div id="carouselQuotes" class="carousel slide quotecaru" data-ride="carousel">
<ol class="carousel-indicators">
    <li data-target="#carouselQuotes" data-slide-to="0" class="active"></li>
    <li data-target="#carouselQuotes" data-slide-to="1"></li>
    <li data-target="#carouselQuotes" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
    ... carousel items ...
</div>
<a class="carousel-control-prev" href="#carouselQuotes" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselQuotes" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
</a>
Run Code Online (Sandbox Code Playgroud)

更改指示器的颜色很容易,因为只需将颜色设置为它们的背景即可。但是为上一个/下一个控件设置背景颜色或颜色并没有改变实际控件图标的颜色。

我发现图标是通过背景图像 SVG 设置的。其中有一部分说明了填充颜色:

.carousel-control-prev-icon {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23fff' viewBox='0 0 8 8'%3E%3Cpath d='M5.25 0l-4 4 4 4 1.5-1.5-2.5-2.5 2.5-2.5-1.5-1.5z'/%3E%3C/svg%3E");
}
Run Code Online (Sandbox Code Playgroud)

我试过

.carousel-control-prev-icon, .carousel-control-next-icon {
    fill: …
Run Code Online (Sandbox Code Playgroud)

css svg background-image twitter-bootstrap-4 bootstrap-4

12
推荐指数
1
解决办法
2万
查看次数