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

ber*_*423 12 css svg background-image twitter-bootstrap-4 bootstrap-4

我有一个带有下一个/上一个控件的 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: #000;
}
.carousel-control-prev-icon, .carousel-control-next-icon {
    fill: '#000';
}
.carousel-control-prev-icon, .carousel-control-next-icon {
    fill: '%23000';
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在不覆盖整个背景图像行的情况下更改图标的颜色?

谢谢

Pau*_*eau 19

您无法使用 CSS 规则设置该 SVG 背景图像的内容样式。它被解析和处理,并在解码时有效地转换为位图图像。

您需要更改 SVG 本身。改变

fill='%23fff'
Run Code Online (Sandbox Code Playgroud)

fill='%23000'
Run Code Online (Sandbox Code Playgroud)

或您想要的任何颜色。这里的“%23”只是“#”符号。在像这样的数据 URI 中使用时,它需要进行URL 编码