css - 在输入框中使用图像作为图标
问题描述
我为此尝试了不同的方法,但没有一个对我有用,所以我问这个问题。
我确实有以下表格
<div className="login-form">
<form className="form-horizontal" id="loginForm">
<div className="form-group" id="username-div">
<input type="email" className="form-control usertext" id="username" placeholder="Email" />
</div>
</div>
</div>
我也尝试使用绝对位置。但不工作。
那么,我该如何解决这个问题?
任何提示或帮助都会有所帮助。
解决方案
有几种方法可以实现这一点,一种是使用绝对定位并将图标放在输入中,但我更喜欢这种方式:
.custom-input {
background-color: white;
border: 2px solid #ededed;
padding: 6px;
width: 215px;
border-radius: 3px;
}
.custom-input>* {
vertical-align: middle;
}
.custom-input img {
width: 25px;
height: 25px;
display: inline-block;
}
.custom-input input {
border: none;
height: 40px;
display: inline-block;
outline: none;
margin-left: 6px;
}
<div class="custom-input">
<img src="https://i.stack.imgur.com/KNLAq.png" alt="user-icon" />
<input type="text" placeholder="username" />
</div>
但是,请注意这不是推荐的方式,在这种情况下最好使用 font-icons。这种情况下已经有很多漂亮、优雅的字体图标。
推荐阅读
- java - Java Swing:如何通过 JLayeredPane 传递鼠标事件
- javascript - 从 MongoDB 检索的 Javascript 对象中删除一个值
- amazon-web-services - AWS 上的 saltstack 最佳实践
- mobile-safari - 在 Safari 中全屏
- reactjs - 两个从属日期选择器,其中开始日期永远不能大于结束日期
- javascript - 如何检测应用程序中按下的键盘组合?
- amazon-web-services - CloudFormation 中更新和导入的区别
- python - Geopandas:保存为csv时如何指定数据类型?
- json - 没有键的结构/映射数组
- json - 如何在 API 调用完成后和组件呈现之前更新状态