我浏览了很多页面,但由于代码结构不同,找不到我想要的答案。因此,我在Forms.py中有一个SelectField和选项列表。
forms.py
def list_fruits():
temp = [('All', 'All Fruits')]
fruits = db.session.query(Fruits.name)
for fruit in fruits:
temp.append((Fruits.name, Fruits.name)
return temp
class FruitsForm(FlaskForm):
fruits = SelectField(u'Fruits', choices=list_fruits(), default = ['All'])
我想使以'A','B'和'C'开头的选项具有红色文本。我该怎么办?
fruits.html
{{ wtf.form_field(form.fruits) }}
我还需要在views.py中做任何事情吗?
CSS nth-child应该可以解决问题。根据页面上有多少个选项,您可以将样式缩小到仅所需的选择字段。
<style>
option:nth-child(-n+3) {
color: green;
}
</style>