如何更改 mdc-select 下拉箭头的颜色?
How to change colour of mdc-select dropdown arrow?
我正在尝试更改 mdc-select:
中下拉箭头的默认紫色
None 的 sass mixin 似乎可以做到这一点。
怎么做到的?
这是我目前尝试过的方法:
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'));
这不是图标或字体,此箭头是 class .mdc-select--focused .mdc-select__dropdown-icon
的背景图片。您可以使用 filter
css 属性.
更改图像颜色
filter: hue-rotate(60deg);
将此 css 应用到您的自定义 css,因为 class .mdc-select--focused .mdc-select__dropdown-icon
它会起作用。
谢谢。
我设法通过使用 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 是在编译时生成的。
最简单最简单的方法是隐藏 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;
}
我正在尝试更改 mdc-select:
中下拉箭头的默认紫色None 的 sass mixin 似乎可以做到这一点。
怎么做到的?
这是我目前尝试过的方法:
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'));
这不是图标或字体,此箭头是 class .mdc-select--focused .mdc-select__dropdown-icon
的背景图片。您可以使用 filter
css 属性.
filter: hue-rotate(60deg);
将此 css 应用到您的自定义 css,因为 class .mdc-select--focused .mdc-select__dropdown-icon
它会起作用。
谢谢。
我设法通过使用 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 是在编译时生成的。
最简单最简单的方法是隐藏 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;
}