【发布时间】:2018-10-05 19:49:54
【问题描述】:
我搜索了上述问题,但我仍然需要堆栈溢出社区的帮助。
在我的登录表单中,我使用了很棒的字体图标。我分别有2个用户名和密码输入框。
我想在用户名输入顶部显示fa-user-cirle 图标。登录表单显示在一个 div 中,如下所示:
<div class="loginDiv">
<form>
<i class="fa fa-user-circle"></i>
<div class="container">
<input type="text" placeholder="Username" name="uname" required>
<input type="password" placeholder="Password" name="psw" required>
<button mat-button (click)="submit()">Login</button>
<label>
<input type="checkbox" checked="checked" name="remember"> Remember me
</label>
</div>
</form>
</div>
图标的 CSS 是:
@import '~@angular/material/theming';
@include mat-core();
$yaana-app-primary: mat-palette($mat-orange, 800,400,200);
.firstDiv {
height: 40%;
width: 100%;
top: 0;
left: 0;
right: 0;
position: absolute;
background-color: orangered;
display: inline-block;
}
.secondDiv {
position: absolute;
width: 100%;
bottom: 0;
height: 60%;
left: 0;
right: 0;
background-color:whitesmoke;
display: inline-block;
}
.loginDiv {
border: 1px solid black;
background: white;
left: 50%;
position: absolute;
top: 28%;
transform: translate(-50%);
background-color: #fff;
padding: 15px;
box-shadow:1px 3px 10px rgba(0, 0, 0, 0.34);
}
input[type=text], input[type=password] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
width: 215px;
height: 36px;
line-height: 36px;
background: transparent;
border-radius: 3px;
will-change: transform;
-webkit-transition: all .2s ease;
transition: all .2s ease;
border: none;
/*border: 2px solid #FF5126;*/
cursor: pointer;
background: #F26722;
font-size: 16px;
color: #fff;
outline: none;
text-align: center;
padding: 0 6px;
margin: 6px 8px;
font-size: 14px;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
text-transform: uppercase !important;
}
button:hover {
opacity: 0.8;
}
.loginImgContainer {
display: table;
max-height: 40px;
max-width: 40px;
}
i.fa {
background: #fff;
display: inline-block;
transform: scale(4,4);
border-radius: 50%;
}
我得到的输出如下:
但我希望图标显示在用户名输入上方和中心。 请帮帮我。
【问题讨论】:
-
请添加完整的css
-
添加完整的 css 或在 fiddle/plunker 中创建工作示例
-
为什么不在输入框前面加上?
-
在您的表单或图标的任何父级中使用
text-align:center。如果您使用scale,图标将继续与输入重叠。然后使用translateY()将其移至表单上方,或删除scale并增加<i>的font-size -
@FridayAmeh 添加了完整的 CSS,但修改了按钮样式
标签: html css font-awesome