【问题标题】:Icon in input field Laravel 4 / Blade输入字段中的图标 Laravel 4 / Blade
【发布时间】:2015-01-24 04:47:28
【问题描述】:

我正在尝试在刀片的输入字段中添加一个图标,看起来像这样

但不要成功。我已经处理了将图标放在按钮上:

{{ HTML::decode(Form::button('<i class="glyphicon glyphicon-check"></i> Send', array('class' => 'btn'))) }}

这就是我将它添加到输入的方式:

{{ HTML::decode(Form::text('From','<i class="glyphicon glyphicon-check"></i> '.Input::get('from'),array('class' => 'myclass', 'id' => 'fromform'))) }}

给出这个输出:

不是我们要找的……

我尝试在标签和输入中添加图标,但没有任何效果。有人有想法吗?

【问题讨论】:

  • 该代码应该可以正常工作。你得到什么输出?
  • 该代码在按钮上运行良好,但我想要输入中的图标,但它不起作用。一秒钟,我会编辑
  • 看看这个solution
  • 谢谢,@Razor 我知道纯 HTML 没问题,但需要刀片的解决方案
  • 在这种情况下我将创建一个macro。

标签: html laravel laravel-4 icons blade


【解决方案1】:

HTML/刀片

 <label class="block clearfix">
 <span class="block input-icon input-icon-right">
 <input class="form-control" placeholder="Username" name="username" type="text" value="">
 <i class="ace-icon fa fa-user"></i>
 </span>
 </label>

示例

希望对您有所帮助。 :)

【讨论】:

    【解决方案2】:

    感谢@Razor,我终于让它工作了,尽管这可能是一种解决方法:

    像这样设置宏:

      {{ Form::macro('myField', function($name, $value = null, $id = null, $class){        
         return '<div class="inner-addon left-addon">
                 <i class="glyphicon '.$class.'"></i>
                 <input type="text" name="'.$name.'" class="myclass" id="'.$id.'" value="'.$value.'"  />
                 </div>';
         }); 
      }}
    

    调用输入:

     {{ Form::myField('From',Input::get('from'),'fromform', 'glyphicon-check') }}
    

    我从 answer 中取出了 css:

    /* enable absolute positioning */
    .inner-addon { 
        position: relative; 
    }
    
    /* style icon */
    .inner-addon .glyphicon {
      position: absolute;
      padding: 10px;
      pointer-events: none;
    }
    
    /* align icon */
    .left-addon .glyphicon  { left:  0px;}
    .right-addon .glyphicon { right: 0px;}
    
    /* add padding  */
    .left-addon input  { padding-left:  30px; }
    .right-addon input { padding-right: 30px; }
    

    如果有人知道实现它的另一种方法,我很高兴听到!

    【讨论】:

      猜你喜欢
      • 2020-01-12
      • 2013-09-09
      • 1970-01-01
      • 2021-02-11
      • 2015-11-28
      • 1970-01-01
      • 2016-05-17
      • 2014-02-06
      • 2011-09-05
      相关资源
      最近更新 更多