gpt4 book ai didi

css - 如何更改轮播中图标的颜色?

转载 作者:行者123 更新时间:2023-11-28 14:28:26 28 4
gpt4 key购买 nike

我开发了一个carousel的功能,我想改变图标的​​颜色(next-icon and previous-icon),可以吗?和 thnak 的(我使用 Angular 5)

文件.html:

 <ngb-carousel [interval]="3000"> 
<ng-template ngbSlide> ... </ng-template>
<ng-template ngbSlide> ... </ng-template>
</ngb-carousel>

_carousel.css:

.carousel-control-prev-icon,
.carousel-control-next-icon {
display: inline-block;
width: $carousel-control-icon-width;
height: $carousel-control-icon-width;
background: transparent no-repeat center center;
background-size: 100% 100%;
}
.carousel-control-prev-icon {
background-image: $carousel-control-prev-icon-bg;
}
.carousel-control-next-icon {
background-image: $carousel-control-next-icon-bg;
}

_variable.css:

$carousel-control-color:            $white !default;
$carousel-control-width: 15% !default;
$carousel-control-opacity: .5 !default;

$carousel-indicator-width: 30px !default;
$carousel-indicator-height: 3px !default;
$carousel-indicator-spacer: 3px !default;
$carousel-indicator-active-bg: $white !default;

$carousel-caption-width: 70% !default;
$carousel-caption-color: $white !default;

$carousel-control-icon-width: 20px !default;

$carousel-control-prev-icon-bg: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' 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"), "#", "%23") !default;
$carousel-control-next-icon-bg: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' viewBox='0 0 8 8'%3E%3Cpath d='M2.75 0l-1.5 1.5 2.5 2.5-2.5 2.5 1.5 1.5 4-4-4-4z'/%3E%3C/svg%3E"), "#", "%23") !default;

$carousel-transition: transform .6s ease !default;

最佳答案

The styles specified in @Component metadata apply only within the template of that component. They are not inherited by any components nested within the template nor by any content projected into the component.

由于 ngb-carousel 是组件内部的嵌套组件,因此您必须将 css 包含在全局 css 文件中。

.carousel-control-prev-icon {

background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' 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");
}

否则,如果您要从您的组件之一添加样式,则可以使用 ::ng-deep

::ng-deep .carousel-control-prev-icon {

background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='#{$carousel-control-color}' 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");
}

检查这个工作 stackblitz

仅供引用,::ng-deep 已弃用,但它仍然有 Angular 。检查this出。

关于css - 如何更改轮播中图标的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54398236/

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