【问题标题】:Icon in input field overlaps输入字段中的图标重叠
【发布时间】:2020-07-08 14:01:16
【问题描述】:

我正在使用 type="text" 的输​​入字段。我在文本框的两侧添加了图标来增加和减少文本框内的数字。它工作正常,直到我增加图标的大小。因为,图标足够大,以至于它与给定的输入重叠。

<mat-form-field >
    <mat-label>Rank</mat-label>
    <input matInput type="text" [(ngModel)]="number">
    <button mat-button matPrefix mat-icon-button>
       <mat-icon style="font-size: 40px">add_box</mat-icon>
    </button>
    <button mat-button matSuffix mat-icon-button>
       <mat-icon style="font-size: 40px">indeterminate_check_box</mat-icon>
    </button>
</mat-form-field> 

如何自定义输入字段,使其不会与给定的输入重叠?

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    尝试像这样使用 flex-box。

    <mat-form-field >
        <mat-label>Rank</mat-label>
        <div style="display:flex;">
            <button mat-button matPrefix mat-icon-button>
                <mat-icon style="font-size: 40px">add_box</mat-icon>
            </button>
            <input matInput type="text" [(ngModel)]="number">
            <button mat-button matSuffix mat-icon-button>
                <mat-icon style="font-size: 40px">indeterminate_check_box</mat-icon>
            </button>
        </div>
    </mat-form-field>
    

    【讨论】:

    • 图标在堆栈中显示。我希望它们在文本框的两侧。
    • 两个图标都在堆栈中,或者您的文本框也与这些图标一起显示在堆栈中
    • 文本框内的图标是堆叠起来的。
    • 不,它应该在每一侧。我认为我们需要自定义输入字段,以便它在图标之间移动。
    • 喜欢这个图标-文本框-图标
    猜你喜欢
    • 2021-08-11
    • 2020-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 2011-09-05
    • 1970-01-01
    相关资源
    最近更新 更多