在表单的输入元素中插入图标的 CSS
要展示如何在表单的输入元素中使用 CSS 放置图标,可以使用 Font Awesome。要在网页上添加 Font Awesome 图标,请包含 CDN −
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
在输入元素中放置图标
我们在这里为用户名、电子邮件和密码使用了 Font Awesome 图标 −
<i class="fa fa-user icon"> </i> <input class="Field" type="text" placeholder="Username" /> <div class="inputContainer"> <i class="fa fa-envelope icon"> </i> <input class="Field" type="text" placeholder="Email" /> </div> <div class="inputContainer"> <i class="fa fa-key icon"> </i> <input class="Field" type="password" placeholder="Password" /> </div>
用户名图标
对于用户名,包含以下图标 −
<i class="fa fa-user icon"> </i>
电子邮件 ID 图标
对于电子邮件 ID,包含以下图标 −
<i class="fa fa-envelope icon"> </i>
密码图标
对于密码,包含以下图标 −
<i class="fa fa-key icon"> </i>
示例
让我们看看在输入元素中放置图标的示例 −
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
form {
max-width: 450px;
margin: auto;
}
.inputContainer i {
position: absolute;
}
.inputContainer {
width: 100%;
margin-bottom: 10px;
}
.icon {
padding: 15px;
color: rgb(49, 0, 128);
width: 70px;
text-align: left;
}
.Field {
width: 100%;
padding: 10px;
text-align: center;
font-size: 20px;
font-weight: 500;
}
</style>
</head>
<body>
<h1 style="text-align: center;">Icons inside input element example</h1>
<form>
<div class="inputContainer">
<i class="fa fa-user icon"> </i>
<input class="Field" type="text" placeholder="Username" />
</div>
<div class="inputContainer">
<i class="fa fa-envelope icon"> </i>
<input class="Field" type="text" placeholder="Email" />
</div>
<div class="inputContainer">
<i class="fa fa-key icon"> </i>
<input class="Field" type="password" placeholder="Password" />
</div>
</form>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP