【问题标题】:How can I add a style to a form element in Symfony 4?如何在 Symfony 4 中为表单元素添加样式?
【发布时间】:2018-08-06 12:50:41
【问题描述】:

我正在使用 Symfony 4 中的 formBuilder:

$form = $this->createFormBuilder($item)
    ->add('username', TextType::class, array('attr' => array('class' => 'form-control')))

我想给表单添加一个样式:

$form = $this->createFormBuilder($item)
    ->add('username', TextType::class, array('attr' => array('style' => 'margin-right:5px'), 'attr' => array('class' => 'form-control')))

我没有看到风格。它没有添加到字段中...

【问题讨论】:

  • 对我来说,你应该像在你提供的第一个代码块上那样添加一个 CSS 类:'attr' => array('class' => 'form-control my-awesome-style ')。否则你可以在树枝模板中做到这一点:symfony.com/doc/current/form/form_customization.html

标签: css forms symfony attributes formbuilder


【解决方案1】:

你有两倍的数组键 attr 所以把它改成:

    ->add('username', TextType::class, array('attr' => array('class' => 'form-control','style' => 'margin-right:5px')))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-27
    • 2020-01-19
    • 2018-01-22
    • 1970-01-01
    • 2018-01-15
    • 2016-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多