如何样式化选择元素的弹出窗口

huangapple go评论86阅读模式
英文:

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;
}

huangapple
  • 本文由 发表于 2023年7月24日 15:57:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76752422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定