html - 如何首先放置 ionic 标签?

标签 html css angular ionic-framework sass

我正在尝试制作一个像新的 google 样式一样的输入标签,但是当我的标签向上移动时,他在中间被切掉了,正如你在这里看到的

enter image description here

我已经尝试更改边距、填充和 Z-index。然后都没有解决我的问题。

我没有使用默认的 ionic 类,因为它不太适合。

如何让标签像谷歌输入一样显示?

我的 SCSS:

.invalid {
  border: 2px solid #f53d3d !important;
}

.danger {
  color: #f53d3d;
}

.item-input {
  margin-top: 5px;
  &.invalid {
    color: red;
  }
}

ion-label.google-label {
  color: #fff;
  background-color: #3880ff;
  font-size: 12px;
  margin-left: 10px !important;
  padding-left: 4px !important;
  padding-right: 4px !important;
  position: absolute !important;
  margin-bottom: 5px !important;
  z-index: 9;
}

ion-input.google-input {
  padding-top: 10px !important;
  color: white;
  border: 2px solid white;
  width: 100%;
  max-width: 100%;
  padding-left: 10px !important;
  border-radius: 5px;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
}

.item-label-floating {
  &.ion-invalid.ion-touched {
    .google-label {
      color: #f53d3d !important;
    }
  }
  &.item-has-value {
    .google-label {
      padding-left: 4px !important;
      padding-right: 4px !important;
      color: #062f77 !important;
      -webkit-transform: translate3d(0, -50%, 0) !important;
      transform: translate3d(0, -50%, 0) !important;
      -webkit-transform-origin: left top;
      transform-origin: left top;
      -webkit-transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
        -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      &.danger {
        color: #f53d3d !important;
      }
    }

    &.ion-valid.ion-touched {
      .google-label {
        color: #fff !important;
      }
    }
  }
  &.item-has-focus {
    .google-label {
      padding-left: 4px !important;
      padding-right: 4px !important;
      color: #062f77 !important;
      -webkit-transform: translate3d(0, -50%, 0) !important;
      transform: translate3d(0, -50%, 0) !important;
      -webkit-transform-origin: left top;
      transform-origin: left top;
      -webkit-transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      transition: color 0.15s cubic-bezier(0.4, 0, 0.2, 1), transform 0.15s cubic-bezier(0.4, 0, 0.2, 1),
        -webkit-transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
      &.danger {
        color: #f53d3d !important;
      }
    }
    .google-input {
      border: 2px solid #062f77;
    }
    &.ion-valid.ion-touched {
      .google-label {
        color: #062f77 !important;
      }
    }
  }
}

我的 HTML:

    <ion-item lines="none">
      <ion-label class="google-label" position="floating" [class.danger]="showErrors('email')">
        E-Mail
      </ion-label>
      <ion-input formControlName="email" class="google-input" [class.invalid]="showErrors('email')" type="text">
      </ion-input>
    </ion-item>

我希望标签显示为这样

enter image description here

最佳答案

对于其他用户,我是这样解决的:

HTML:

    <div class="label-float" [class.invalid]="showErrors('email')">
      <input type="text" formControlName="email" placeholder=" " />
      <label>E-Mail</label>
    </div>

SCSS:

.label-float {
  position: relative;
  padding-top: 13px;
  &.invalid {
    label {
      color: #f53d3d !important;
    }
    input {
      border: 2px solid #f53d3d !important;
    }
  }

  input {
    background-color: transparent;
    border: 2px solid #fff;
    border-radius: 5px;
    outline: none;
    min-width: 250px;
    padding: 15px 20px;
    font-size: 16px;
    transition: all 0.1s linear;
    -webkit-transition: all 0.1s linear;
    -moz-transition: all 0.1s linear;
    -webkit-appearance: none;
    &:focus {
      border: 2px solid #3951b2;
    }
    &::placeholder {
      color: transparent;
    }
  }
  label {
    color: #fff;
    pointer-events: none;
    position: absolute;
    top: calc(50% - 8px);
    left: 20px;
    transition: all 0.1s linear;
    -webkit-transition: all 0.1s linear;
    -moz-transition: all 0.1s linear;
    background-color: #3880ff;
    padding-top: 5px;
    margin-left: 10px;
    padding-left: 4px;
    padding-right: 4px;
    box-sizing: border-box;
  }
}

.label-float input:focus + label,
input:not(:placeholder-shown):not(.invalid) + label {
  font-size: 13px;
  top: 0;
  color: #3951b2;
}
.label-float input:not(:focus):not(:placeholder-shown):not(.invalid) + label {
  font-size: 13px;
  top: 0;
  color: #fff;
}

关于html - 如何首先放置 ionic 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56895267/

相关文章:

php - 更新表格行中的数据[PHP]

html - 左侧边栏与内容区域高度相同,页脚位于浏览器窗口底部

javascript - chrome 中的页面闪烁 - bootstrap 和 jquery 冲突

angular - 标识符 'required' 未定义。 '__type' 不包含这样的成员

angular - Angular 2 中的全局管道

javascript - 以编程方式显示基于 IP 国家/地区的 Div

html - 在 Tailwind CSS 中制作动画标签?

javascript - jquery 脚本 : z-index and setTimeout 的两个问题

css - bootstrap 如何仅使用 css 在特定视口(viewport)宽度下折叠列?

angular - 函数在 5000 毫秒后超时 - Angular 4 - Protractor 和 cucumber