代码之家  ›  专栏  ›  技术社区  ›  karlo1zg

垂直对齐输入元素中间的浮动标签

  •  1
  • karlo1zg  · 技术社区  · 9 年前

    所以,我不想使用占位符,相反,我想使用离子标签一样的占位符。我需要垂直对齐 漂浮

    这是我目前得到的:

        <ion-item>
          <ion-label floating class="label__placeholder">SMS</ion-label>
          <ion-input name="first_name"
            type="text"
            ngModel
            required>
          </ion-input>
        </ion-item>
    

    SCS:

        ion-label {
          font-family: 'Roboto', sans-serif;
          font-size: 18px !important;
          margin-bottom: 5px;
          padding-left: 15px;
    
          &.label__placeholder {
            position: absolute;
            bottom: 30px;
          }
        }
    

    这是现在的图片,以及未点击离子输入时离子标签的外观:

    enter image description here

    这是当我点击离子输入时,离子标签在离子输入的顶部,但它不可见:

    enter image description here

    点击ion input时应该是这样的:

    enter image description here

    我设法将离子标签放置在离子输入的中间,但当我单击离子输入时,离子标签位于离子输入的顶部,它不可见,好像它在后面的某个地方,不知道在哪里。也尝试使用z索引,但没有任何帮助。

    1 回复  |  直到 9 年前
        1
  •  1
  •   karlo1zg    9 年前

    我设法解决了这个问题。我从&中删除了位置:绝对和底部:30px;。label\uu placeholder并使用此代码,它可以工作:

        ion-label {
          font-family: 'Roboto', sans-serif;
          font-size: 18px !important;
          padding-left: 15px;
          &.label__placeholder {
            font-size: 15px !important;
            line-height: 13px;
            margin-bottom: 0 !important;
          }
        }
    

    以下是未单击离子输入和单击离子输入时的外观: enter image description here

    enter image description here