Ryo
Ryo

Reputation: 1035

Yii2 - set label position for input field

I using form field and set label like this :

     <?= $form->field($unit, 'estimated_time')->textInput(['style' => 'width: 50px'])->label("Minutes") ?>

but label display in the left side of input-field How can I display it in right side ?

Upvotes: 2

Views: 8193

Answers (3)

vkabachenko
vkabachenko

Reputation: 261

I think better solution is

<?= $form->field($unit, 'estimated_time', [
   'template' => '{input}{label}{error}{hint}',
   'options' => ['class' => 'form-group form-inline'],]
   ->textInput([
    'style' => 'width: 50px; margin-right: 10px;']); ?>

Upvotes: 6

jithin
jithin

Reputation: 920

Assign style for your input like below:

<?= $form->field($unit, 'estimated_time', [
    'template' => '<div style="float:right;">{label}</div>{input}{error}{hint}'
]);?>

more reference http://www.yiiframework.com/doc-2.0/yii-bootstrap-activefield.html

Upvotes: 0

Manoj S Kadlag
Manoj S Kadlag

Reputation: 250

Try this :

 <?= $form->field($unit, 'estimated_time')->textInput(['style' => 'width: 50px'])->label('Your Label',['class'=>'label-class']) ?>

Add css as

.label-class{
   float: right;
}

Upvotes: 0

Related Questions