我正在尝试在mdc-select中更改下拉箭头的默认紫色:
似乎没有混蛋。
如何完成?
这是我到目前为止尝试过的:
HTML
<div class="mdc-select mdc-select--outlined">
<input type="hidden" name="enhanced-select">
<i class="mdc-select__dropdown-icon"></i>
<div class="mdc-select__selected-text" class="mdc-select__selected-text" role="button" aria-haspopup="listbox" aria-labelledby="demo-label"></div>
<div class="mdc-select__menu mdc-menu mdc-menu-surface">
<ul class="mdc-list">
<li class="mdc-list-item" data-value="41" role="option">41</li>
<li class="mdc-list-item" data-value="42" role="option">42</li>
<li class="mdc-list-item" data-value="43" role="option">43</li>
</ul>
</div>
<div class="mdc-notched-outline">
<div class="mdc-notched-outline__leading"></div>
<div class="mdc-notched-outline__notch">
<label class="mdc-floating-label">Answer to Life</label>
</div>
<div class="mdc-notched-outline__trailing"></div>
</div>
</div>
SCSS
@import "@material/list/mdc-list";
@import "@material/menu-surface/mdc-menu-surface";
@import "@material/menu/mdc-menu";
@import "@material/select/mdc-select";
.mdc-select {
@include mdc-select-ink-color(red);
// @include mdc-select-container-fill-color(red);
@include mdc-select-label-color(red);
@include mdc-select-focused-label-color(red);
@include mdc-select-bottom-line-color(red);
@include mdc-select-focused-bottom-line-color(red);
@include mdc-select-hover-bottom-line-color(red);
@include mdc-select-outline-color(red);
@include mdc-select-focused-outline-color(red);
@include mdc-select-hover-outline-color(red);
@include mdc-select-icon-color(red);
}
TS
import { MDCSelect } from '@material/select';
const select = new MDCSelect(document.querySelector('.mdc-select'));
答案 0 :(得分:2)
这不是图标或字体,该箭头是类.mdc-select--focused .mdc-select__dropdown-icon
的背景图像。您可以使用filter
css属性来更改图像颜色。
filter: hue-rotate(60deg);
将此css应用于类.mdc-select--focused .mdc-select__dropdown-icon
的自定义css,它将起作用。
谢谢。
答案 1 :(得分:0)
我设法通过使用MDC内部Sass mixin:mdc-select-dd-arrow-svg-bg_
为其设置了主题。一个例子是:
.mdc-select .mdc-select__dropdown-icon {
@include mdc-select-dd-arrow-svg-bg_(COLOR, 1);
}
其中COLOR
是MDC主题属性(例如'secondary'
)或HTML颜色(例如#ff0000
)。它不能是var,因为正如@KuldipKoradia指出的那样,在编译时会生成SVG。
答案 2 :(得分:0)
最简单的方法是隐藏SVG,并通过CSS创建自己的下拉箭头(无需更改HTML)。然后,您可以根据需要轻松地频繁更改颜色:
.mdc-select__dropdown-icon{
background: none;
width: 0;
height: 0;
bottom: 24px;
right: 10px;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #333333;
}
.mdc-select--activated .mdc-select__dropdown-icon,
.mdc-select--focused .mdc-select__dropdown-icon {
border-top: 5px solid #FF0000;
}