【发布时间】:2019-12-10 15:55:17
【问题描述】:
我正在使用ng-style 在团队列表中标记类似团队标签的东西,我想让团队的名称将根据填充团队名称覆盖区域背景的颜色来更改.问题是如果背景颜色的亮度会变暗,文本颜色会导致团队名称变暗,用户无法阅读。那我该怎么做呢?
- HTML:
<tr ng-repeat="team in teams">
<td>{{ team.id }}</td>
<td><span ng-style="setColor(team.color)" style="color: #888;">{{ team.name }}</span></td>
</tr>
- 控制器:
app.controller('teamController', function($scope){
$scope.teams = [
{
id: '1',
name: 'Driver',
color: '#b9774d'
},
{
id: '2',
name: 'Finance',
color: '#FEFFB3'
}
];
$scope.setColor = function (color){
return {background: color};
}
});
【问题讨论】:
-
css-tricks上有一篇文章非常透彻地讨论了这个案例,你应该看看。
-
感谢您的回答,我会阅读这篇文章以更深入地挖掘 css。 =D
标签: javascript css angularjs ng-style