html - 如何在输入字段开头的圆圈内放置一个图标?

标签 html css ionic-framework

我试图在圆圈内放置一个图标,该圆圈将放置在输入字段的开头,如下所示:

enter image description here

我正在尝试使用 ionic 中的以下代码实现此目的:

//在 .html 中

<ion-row>
  <ion-item>
    <ion-label> <ion-icon name="person"></ion-icon></ion-label>
    <ion-input clearInput type="text"></ion-input>
  </ion-item>
</ion-row>

//在 .scss 中

ion-item {
  border-radius: 23px;
  padding-left: 0;
}

ion-label {
    border-radius: 23px;
    border: 2px solid red;
    width: 12%;
    height: 100%;
}

但我只能做到以下几点:

enter image description here

谁能帮我解决这个问题?

最佳答案

您需要为 label 图标使用 position:absolute...并对标签使用 display:flex 以对齐图标里面居中

注意:我在这里使用 font-awesome 只是为了图标视觉...

ion-item {
  position: relative;
}

ion-label {
  border-radius: 50%;
  border: 2px solid red;
  position: absolute;
  top: 0;
  left: 0;
  width: 46px;
  height: 46px;
  z-index: 9;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

input {
  border: 1px solid;
  height: 46px;
  width: 100%;
  display: block;
  border-radius: 23px;
  box-sizing: border-box;
  padding-left: 50px;
  outline: none;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<ion-row>
  <ion-item>
    <ion-label><i class="fa fa-user"></i></ion-label>
    <input clearInput type="text">
  </ion-item>
</ion-row>

关于html - 如何在输入字段开头的圆圈内放置一个图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49398684/

相关文章:

html - 当子元素超出父 div 的宽度时,如何防止水平滚动?

javascript - 显示内部 html 需要覆盖/灯箱

css - sibling div 不占用位置相对且顶部为负的 div 的空间

jquery - 如何使用 JQuery 缓动菜单栏上的图像 "uncover"

javascript - Controller 的未知提供程序错误

javascript - 在 Angular 4 中 Plotly 找不到带有 ngIf 的 HTML 元素

javascript - 调用 javascript 函数时如何将 javascript touch spin 添加到 html

css - 如何使用 ng-hide/ng-show 动画

css - 在中心获得 ionic radio

font-face - 自定义字体未在 ionic 框架中加载