英文:
How to style a select element's popup
问题
vaadin-select-item.search-bar_popup {
background: black;
color: white;
}
英文:
I'm trying to style the Select element's popup window (the window that opens when you go to select an item).
I can correctly target the popup via the following CSS:
vaadin-select-item {
background: black;
color: white;
}
The problem is that this sets the popup globally where as I only want this styling to apply to this specific element.
I've set the following class names:
var droplist = new Select<SearchType>();
droplist.addClassName("search-bar");
droplist.setOverlayClassName("search-bar_popup");
I can target the main drop list with:
vaadin-select.search-bar::part(toggle-button) {
color: white;
}
The Vaadin documentation on styles is rather limited.
But when I try to target the popup the CSS fails to target the element:
vaadin-select-item.search-bar_popup {
background: black;
color: white;
}
答案1
得分: 1
.overlay-classname 应用于覆盖元素,而不是覆盖中的各个项目。项目是覆盖的常规子元素,因此使用 search-bar
作为 overlay-classname,你可以这样目标它们:
/* 样式整个选择元素 */
.search-bar vaadin-select {
height: 58px;
width: 120px;
align-content: center;
flex-wrap: wrap;
}
/* 搜索类型下拉列表 */
.search-bar vaadin-select-item {
background: black;
color: white;
}
/* 样式下拉箭头 */
.search-bar vaadin-select::part(toggle-button) {
color: white;
}
/* 样式弹出窗口 */
.search-bar_popup vaadin-select-item {
background: black;
color: white;
}
英文:
The overlay-classname is applied to the overlay-element, not to individual items in the overlay. The items are regular child elements of the overlay, so with an overlay-classname of search-bar
you would target them like so:
/* style the overall select element */
.search-bar vaadin-select {
height: 58px;
width: 120px;
align-content: center;
flex-wrap: wrap;
}
/* search type drop list */
.search-bar vaadin-select-item {
background: black;
color: white;
}
/* style the drop arrow */
.search-bar vaadin-select::part(toggle-button) {
color: white;
}
/* style the popup window */
.search-bar_popup vaadin-select-item {
background: black;
color: white;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论