css - ng-bootstrap - Typeahead 下拉宽度

标签 css angular bootstrap-4 ng-bootstrap

我开始使用 ng-bootstrap Typeahead 组件,我对此非常满意。

我想实现的一件事是让下拉项具有与输入字段相同的宽度,而默认行为会根据文本长度应用宽度。它应该是基本的 CSS...

我创建了一个基本的 Example在 Plunker 中。

正如您所注意到的,应用的样式被忽略了:

.dropdown-menu { width: 100%;}

而如果我使用浏览器开发工具,并应用相同的工具。

关于如何通过使用 CSS 实现结果有任何想法吗?

最佳答案

在组件中添加封装:ViewEncapsulation.None

import {Component, ViewEncapsulation} from '@angular/core';

@Component({
  selector: 'ngbd-typeahead-template',
  templateUrl: 'src/typeahead-template.html',
  styleUrls: ['src/typeahead-template.css'],
  encapsulation: ViewEncapsulation.None
})

查看更新 plunker

如果没有 ViewEncapsulation.None,该组件中应用的样式只会影响该组件,而不会影响该页面上的任何其他组件。

阅读this了解更多信息

关于css - ng-bootstrap - Typeahead 下拉宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51416897/

相关文章:

javascript - 为什么我的媒体查询不起作用?

html - 在桌面上使用缩放而不是断点

javascript - Angular2 如何管理依赖注入(inject)?

css - 即使在使用 'collapse in' 类后,div 最初也会折叠

javascript - Angular 2 : Open ngbPopover containing image delayed on hover

css - 使用 Bootstrap 4,如何在右侧对齐 navbar-brand?

html - 如何使 div 的一部分隐藏在屏幕之外?

html - 如何创建两个div元素,左边固定宽度,右边动态宽度

javascript - TS - 使用 return 从回调函数中分配值

带报告的 Angular 最佳静态代码分析工具