我想在项目中使用ng-tags-input。
我尝试根据数组中的颜色属性对象为每个标签设置不同的颜色。
这是我正在研究的pl子。
为此,我需要在ng-input模板中覆盖tag-item css类。
这是ng-input模板的示例:
<script type="text/ng-template" id="tag-template">
<div class="tags-input" ng-style="{background: data.color}">
<span>{{$getDisplayText()}}</span>
<a class="remove-button" ng-click="$removeTag()">✖</a>
</div>
在这一行中,我尝试覆盖tags-input css类:
<div class="tags-input" ng-style="{background: data.color}">
这是我得到的结果:
如您所见,左右边缘未着色。
知道我在做什么错吗?以及如何覆盖标签输入CSS类?
如果查看标记,您会看到将背景颜色样式应用到的.tags-input div嵌入到li
元素中,该元素的尾部和右侧填充为5px。这就是为什么颜色未应用在按钮的整个宽度上的原因。
因此,请确保在ng-tags-input样式表之后应用您自己的样式表,并覆盖一些CSS规则li
以使不会填充,而具有背景颜色的div则具有填充:
/* override default tag styles for colors to look less ugly */
tags-input .tags .tag-item {
padding: 0;
height: 27px;
}
.tags-input {
padding: 0 5px;
border-radius: 2px;
}
这是修改您的plunkr来实现的目标。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句