更改SVG背景图像的颜色(Bootstrap 4轮播) [英] Change color of SVG background-image (Bootstrap 4 carousel)
问题描述
到目前为止,我有一个带有next/prev控件的BS 4传送带.我的背景较浅,因此我想更改控件的颜色(当前为白色).
I have a BS 4 carousel with next/prev controls which works so far. I have a light background so I would like to change the color of the controls (currently white).
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>
更改指示器的颜色非常容易,因为只需将颜色设置为背景即可.但是为上一个/下一个控件设置背景颜色或颜色并不会更改实际控件图标的颜色.
Changing the color of the indicators was easy since that's simply set with a colour as their background. But setting background-color or color for the prev/next controls didn't change the color of the actual control icon.
我发现图标是通过背景图像SVG设置的.其中有一部分说明填充颜色:
I found that the icons are set via background-image SVG. There is a part of it stating the fill color:
.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");
}
我尝试过
.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';
}
是否可以在不覆盖整个背景图像行的情况下更改图标的颜色?
Is there a way to change the color of the icon without overriding the entire background-image line?
谢谢
推荐答案
您无法使用CSS规则为该SVG背景图像的内容设置样式.对其进行解析和处理,并在解码时有效地转换为位图图像.
You can't style the contents of that SVG background image using CSS rules. It is parsed and processed and effectively turned into a bitmap image as it's decoded.
您需要更改SVG本身.更改
You would need to alter the SVG itself. Change the
fill='%23fff'
到
fill='%23000'
或您想要的任何颜色.这里的%23"只是#"符号.在像这样的数据URI中使用时,它必须是 URL编码.
or to whichever colour you wish. The "%23" here is just the "#" symbol. It needs to be URL-encoded when used in a Data URI like this.
div {
background-color: black;
}
button {
width: 24px;
height: 24px;
border: none;
background-color: transparent;
}
.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");
}
div.inverted {
background-color: white;
}
.inverted .carousel-control-prev-icon {
background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23000' 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");
}
<div>
<button class="carousel-control-prev-icon"></button>
</div>
<div class="inverted">
<button class="carousel-control-prev-icon"></button>
</div>
这篇关于更改SVG背景图像的颜色(Bootstrap 4轮播)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!