input框中放置图标

一、使用标签<i>存放图标,利用绝对定位调整位置,图标图层需要在input之上
二、在input内直接使用背景图片放在图标,利用background-position调整位置
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>输入框小图标</title>
    <style type="text/css">
     .box01{
        color: #434343;
        position: relative;
        margin-bottom: 20px;
     }
     .box01 input{
         -webkit-appearance: none;
         -moz-appearance: none;
         appearance:none ;
         outline: 0;
         width: 270px;
         height: 30px;
         border:0px solid #fff;
         border-radius: 20px;
         box-shadow:0 0 5px 2px rgba(0,0,0,0.1);
         padding: 0 30px 0 15px;
     }
     .box01 label{
         font-size: 16px;
         z-index: 2;
         position: absolute;
         left: 109px;
         top:15%;
         color: #b2b2b2;
     }
     /*利用<i>来安放图标*/
     .icon{
         display: inline-block;
         height: 16px;
         width: 16px;
         background-image: url(search.svg);/*这里放置图标的绝对路径*/
         background-repeat: no-repeat;
         position: absolute;
         top: 24%;
         left: 290px;
         z-index: 2;
     }
     /*利用背景图片安放图标*/
     #tip02{
         padding: 0 10px 0 35px;
         background-image: url(search.svg);
         background-repeat: no-repeat;
         background-position: 10px 7px;
     }
     
    </style>
</head>
<body>
    <div class="box01">
        <input type="text" id="tip" placeholder="搜索你喜欢的">
        <i class="icon"></i>
    </div>
    
    <div class="box01"><input type="text" id="tip02" placeholder="fine your need"></div>
 
</body>
</html>

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值