yii2 修改验证码小部件样式

<?= $form->field($model, 'verifyCode',['labelOptions' => ['class' => 'yanzhengma','style'=>['margin-right'=>'50px']]])->widget(Captcha::className()) ?>

生成的代码

<div class="form-group field-signupform-verifycode">
  <label class="yanzhengma" style="margin-right: 50px;" for="signupform-verifycode">验证码</label>
  <img id="signupform-verifycode-image" src="/frontend/web/index.php?r=site%2Fcaptcha&amp;v=5a17ff5fc8f06" alt=""> <input type="text" id="signupform-verifycode" class="form-control" name="SignupForm[verifyCode]">
   
  <p class="help-block help-block-error"></p>
  </div>

以下为主要的样式修改的代码,大家可以看着修改。如需要修改类而不是样式,只需要替换style为class即可。

[php] view plain copy
 
  1. <?php $form = ActiveForm::begin(['action' => ['site/login'], 'method' => 'post']);?>  
  2.     <div style='255px;min-height:40px;height:auto;'>  
  3.         <label for='loginform-username' style='margin-right:10px;line-height:2.2em;float:left;'>用户名</label>  
  4.         <?= $form->field($model, 'username')  
  5.             ->label(false)  
  6.             ->textInput(['style' => 'float:left;200px;'])  
  7.             ->error(['style' => 'line-height:2.2em;']); ?>  
  8.     </div>  
  9.     <div style='255px;min-height:40px;height:auto'>  
  10.     <label for='loginform-username' style='padding-left:13px;margin-right:10px;line-height:2.2em;float:left;'>密码</label>  
  11.     <?= $form->field($model, 'password')  
  12.         ->passwordInput()  
  13.         ->label(false)  
  14.         ->textInput(['style' => 'float:left;200px;'])  
  15.         ->error(['style' => 'line-height:2.2em;']); ?>  
  16.     </div>  
  17.     <div style='255px;min-height:20px;height:auto'>  
  18.         <?= $form->field($model, 'rememberMe')  
  19.         ->checkBox(['style' => 'flot:left;'])  
  20.         ->label('请记住我', ['style' => 'margin-right:-35px;']); ?>  
  21.     </div>  
  22.   
  23.     <?= Html::submitButton('登录', ['class' => 'btn btn-primary', 'name' => 'submit-button']); ?>  

yii2 传值给页面

return $this->render('jiekou',[
'value' => $data,
]);

<div class="country-create">
<?= Html::encode($this->title) ?>
<!-- <?=Html::encode($value->message)?> -->
<?php print_r($value)?>

</div>

原文地址:https://www.cnblogs.com/yszr/p/7892034.html