<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/*子绝父相设置定位模式*/
.input-container{
position:relative;
display: inline-block;
}
.input-icon{
position:absolute;
top:4px;
right:4px;
height:75%;
width:32px;
text-align:center;
}
/**使用伪元素垂直居中*/
.input-icon::before{
content: '\E900';
vertical-align: middle;
}
.input-icon:after{
content:'';
display: inline-block;
vertical-align: middle;
height:100%
}
.input-text{
padding-left:32px;
height:32px;
line-height:1;
outline:0;
appearance: none;
-webkit-appearance:none;
border:1px solid #ccc;
background-color: #fff;
border-radius:2px;
padding:3px 8px;
box-sizing: border-box;
width:100%;
}
.input-text:focus{
outline:0;
border-color:#666;
}
</style>
</head>
<body>
<div class="input-container">
<i class="input-icon"></i>
<input type="text" class="input-text" placeholder="搜索">
</div>
</body>
</html>
输入框(使用伪元素 确保 icon垂直居中 还有 75%=(32-4*2)/32计算出来的,border-box中 width=content+border+padding,height同理)
最新推荐文章于 2022-10-21 21:57:30 发布