【问题标题】:Django - how to style the placeholder of a form field?Django - 如何设置表单字段的占位符?
【发布时间】:2014-04-11 20:02:44
【问题描述】:

好的,所以我已经安装了 django-registration 应用程序,并且对于注册功能,我添加了一个用于电子邮件的小部件以制作占位符:

email = forms.EmailField(label=_("E-mail"),
                         widget=forms.TextInput(attrs={'placeholder': 'Your Email'}))

我更喜欢使用占位符,而不是标签。

现在,我的问题是:如何设置占位符的样式?添加一些颜色,更改占位符大小和字体等 谢谢

【问题讨论】:

标签: django forms widget styles registration


【解决方案1】:

我也遇到过这个问题,但后来我意识到您不想在 Django 表单中设置占位符的样式。只需将以下 css 添加到您的样式表中即可。

::-webkit-input-placeholder {
   color: rgba(255, 255, 255, .5);
}

:-moz-placeholder { /* Firefox 18- */
   color: rgba(255, 255, 255, .5);
}

::-moz-placeholder {  /* Firefox 19+ */
   color: rgba(255, 255, 255, .5);
}

:-ms-input-placeholder {
   color: rgba(255, 255, 255, .5);
}

【讨论】:

    【解决方案2】:

    你可以这样做。

    email = forms.EmailField(label=_("E-mail"),
                         widget=forms.TextInput(attrs={'placeholder': 'Your Email', 'class':'your_css_code'}))
    

    【讨论】:

      猜你喜欢
      • 2020-04-09
      • 2014-08-27
      • 2020-11-29
      • 2019-08-17
      • 1970-01-01
      • 2017-10-23
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多