django-crispy-forms input size

无人久伴 提交于 2019-12-23 09:31:28

问题


According with django-crispy-form documentation, I will be able to change input width with class input-small. But my form always looks with width at 100%:

Also, If I add css_class to Field the size remains at width:100% ( .form-control )

I have set form as documentation explains:

class LoginForm(forms.Form):
    usuari = forms.CharField( help_text = u'Codi Usuari')
    paraula_de_pas = forms.CharField( help_text = u'Paraula de pas')

    # Uni-form
    helper = FormHelper()
    helper.form_class = 'form-horizontal'
    helper.label_class = 'col-lg-2'  
    helper.field_class = 'col-lg-8'  
    helper.layout = Layout(
        PrependedText('usuari', 
                      '<span class="glyphicon glyphicon-user"></span> ',  
                      css_class='input-small'),
        PrependedText('paraula_de_pas', 
                      '<span class="glyphicon glyphicon-asterisk"></span> ', 
                      css_class='input-small'),
        FormActions(
            Submit('save_changes', 'Entrar-hi', css_class="btn-primary"),
        )
    )

In settings:

CRISPY_TEMPLATE_PACK="bootstrap3"

I'm up to date version. What is wrong?


回答1:


  • In bootstrap3 class name for small input box is input-sm
  • input-sm just sets size of the font and height of the field, it has nothing to do with field width.

form-horizontal, col-lg-2 and col-lg-8 make horizontal layout for the form (http://getbootstrap.com/css/#forms-horizontal). So first of all make sure your screen resolution to enough for lg. Try col-sm-*



来源:https://stackoverflow.com/questions/22746944/django-crispy-forms-input-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!