如何在类中添加CSS类

时间:2018-07-23 10:40:46

标签: css class

我有非常大的数据,我想按州动态上课。

"<td> 
    <i class='fullPassengerListState_" + data[i].State + "'>"
     + data[i].State + "
    </i>
</td>"

我想要这个

fullPassengerListState_1类应该是fa-check(字体真棒)

fullPassengerListState_0类应该是fa-times(Font Awesome)

我不想使用if(data [i] .state == 0)或类似的东西。

1 个答案:

答案 0 :(得分:1)

通过pesudo :before.fullPassengerListState_1/0在CSS中简单地做到这一点:

注意! 我以“真棒字体5”为例

.fullPassengerListState_1:before{ 
  content:'\f00c';
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
}
.fullPassengerListState_0:before{ 
  content:'\f00d';
  font-family: 'Font Awesome 5 Free';
  font-weight: 900;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" integrity="sha384-O8whS3fhG2OnA5Kas0Y9l3cfpmYjapjI0E4theH4iuMD+pLhbf6JI0jIMfYcK3yZ" crossorigin="anonymous">


<i class='fullPassengerListState_0'> state 0
</i>
<i class='fullPassengerListState_1'> state 1
</i>