首先,我的目标是使两个输入字段内联,图片是附件:
Symfony允许我们通过对字段的form_widget使用attr和对form_label使用label_attr来设置表单字段的样式,但在这里我想对div应用一个样式,该div包含Symfony在分支中自动生成的label + input:
$builder
->add('language', ChoiceType::class, array(
'choices' => array(
'FR' => 5,
'EN' => 1,
),
'label' => ' ',
'attr' => array('style' => 'float:left;width:40%'),
))
->add('level', ChoiceType::class, array(
'choices' => array(
'Good' => 5,
'Bad' => 1,
),
'label' => ' ',
'attr' => array('style' => 'float:left;width:40%'),
));
result:样式已经应用到输入(在我们的例子中是select),div父项没有受到影响(保持空样式):
<div id="homebundle_personnel_personnelLanguages_0">
<div> <!-- the div that i want to apply a style -->
<label for="homebundle_personnel_personnelLanguages_0_language" class="required"> </label>
<select id="homebundle_personnel_personnelLanguages_0_language" name="homebundle_personnel[personnelLanguages][0][language]" style="float:left;width:40%">
<option value="5">FR</option>
<option value="1">EN</option>
</select>
</div>
<div>
<label for="homebundle_personnel_personnelLanguages_0_level" class="required"> </label>
<select id="homebundle_personnel_personnelLanguages_0_level" name="homebundle_personnel[personnelLanguages][0][level]" style="float:left;width:40%">
<option value="5">Good</option>
<option value="1">Bad</option>
</select>
</div>
</div>
2条答案
按热度按时间a1o7rhls1#
下定决心,我必须在小枝的层面上对待这一点:
c2e8gylq2#
用途: