简体   繁体   English

在表单字段yii2中添加图像

[英]Adding image in form field yii2

I need to add image into form field in yii2. 我需要将图像添加到yii2的表单字段中。 I can't find an example for how can I do that.I need to do something like that: 我找不到如何执行此操作的示例,我需要执行以下操作: 在此处输入图片说明

I know how to add placeholder and do that, but dont know how to add the image. 我知道如何添加占位符并执行此操作,但不知道如何添加图像。

<?= $form->field($model, 'email')->textInput()->input('email',['placeholder' => "E-mail"])->label(false); ?>

I think the Easiest way to do it will be with CSS. 我认为最简单的方法是使用CSS。

<div class="input_container">
    <span class="input_placeholder_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></span>
    <?= $form->field($model, 'email')->textInput()->input('email',['placeholder' => "E-mail"])->label(false); ?>
</div>

And in your CSS: 在您的CSS中:

.input_container{
position: relative;
}

.input_placeholder_icon{
position: absolute;
top: 2px;
color: red;
left: 2px;
font-size: 21px;
width: 50px;
}

You can change some settings in CSS depending on your need. 您可以根据需要更改CSS中的某些设置。 I have used font-awesome icon in the example. 我在示例中使用了真棒字体图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM