【问题标题】:Is there a way with CSS to add space between the cursor, and the placeholder text in an input?CSS有没有办法在光标和输入中的占位符文本之间添加空格?
【发布时间】:2015-08-20 21:45:02
【问题描述】:

我的问题与在早期版本的 Firefox for OSX (37.0.2) 上发现的错误有关,我在此处截屏:http://i.imgur.com/s6AfHuP.png

有没有办法用 css 将占位符的第一个字符从光标最初所在的位置移开?

该页面是一个 Angular 应用程序,我听说它有时不能很好地与 Firefox 配合使用。

我尝试将 text-indent 和 padding-left 添加到 moz-placeholder,但这会使光标与占位符文本一起移动。

在所有版本的 Firefox 中,我还构建了一些 JS 来为占位符文本添加空格,但我希望避免这样做。

【问题讨论】:

标签: javascript jquery html css angularjs


【解决方案1】:

我建议要么生成所有带有前导空格的占位符,如前所述,要么直接使用::-moz-placeholder { font-style: italic; }

【讨论】:

    【解决方案2】:

    是的,您可以在 CSS 中使用不会折叠空格的 white-space: pre; 属性在占位符文本中显示前导空格。

    例如:如果您正在使用 Angular 多选下拉菜单,则应使用下面显示的类似代码在占位符文本中呈现前导空格.

    <ng-select style="white-space: pre" placeholder="  Example of a placeholder with leading spaces!" [multiple]="xxxx" [formControl]="xxxx">                                                    
         <ng-option *ngFor="let x of y" [value]="x?.value">{{x?.text}}</ng-option>                                                
    </ng-select> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-21
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 2018-09-29
      • 2020-10-09
      • 1970-01-01
      • 2013-01-18
      相关资源
      最近更新 更多