HTML input框里加图标

 加一个小图标

<div class="userInput">
   <input type="text" placeholder="请输入登录账号">
</div>
<div class="passwordInput">
   <input type="text" placeholder="请输入登录密码">
</div>

<style>
    .userInput input {
        background: url(./imgs/userIcon.png) no-repeat;
        background-position: 12px;
        padding-left: 40px;
  }
    .passwordInput input {
        background: url(./imgs/passwordIcon.png) no-repeat;
        background-position: 12px
        padding-left: 40px;
  }
</style>

在input里加背景图  background-position设置背景图的位置

 

 

 加两个小图标(使用position定位的方法)

<div class="password">
    <img src="./imgs/passwordIcon.png" class="leftImg">
    <input type="password" placeholder="请输入登录密码" class="passwordInput">
    <img src="./imgs/expend.png" class="rightImg">
</div>


<style>
.password {
    position: relative;
    margin-top: 20px;
    z-index: 1;
}
.passwordInput {
    position: absolute;
    box-sizing: border-box;
    left: 0;
    width: 440px;
    height: 48px;
    padding-left: 40px;
    border: 1px solid #222222;
    line-height: 22px;
    font-size: 16px;
    font-weight: 400;
    color: #687177;
    z-index: -1; //设置输入框在图标下层
 }
.leftImg {
    float: left;
    margin: 16px 12px;
}
.rightImg {
    float: right;
    margin: 17px 12px;
    cursor: pointer;
}
</style>

  • 3
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值