[英]How to make font awesome icon appear at centre inside a div
I Googled for the above mentioned problem, but I still require the help from the stack overflow community. 我用谷歌搜索了上述问题,但是我仍然需要堆栈溢出社区的帮助。
In my login form, I am using font awesome icon. 在我的登录表单中,我正在使用字体超赞图标。 I have 2 input boxes for username and password respectively.
我有2个输入框,分别用于用户名和密码。 I want to display
fa-user-cirle
icon on top of the username input. 我想在用户名输入上方显示
fa-user-cirle
图标。 The login form is displayed in a div as follows: 登录表单显示在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>
The CSS for icon is: 图标的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%;
}
The output I am getting is as follows: 我得到的输出如下:
But I want the icon to appear just above the username input and at the centre. 但我希望该图标出现在用户名输入上方和中间。 Please help me.
请帮我。
Try with adding row above the container, 尝试在容器上方添加行,
<div class="loginDiv">
<form>
<div class="row center">
<i class="fa fa-user-circle"></i>
</div>
<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>
Thanks for giving me hint and found out the solution with following changes in css, 感谢您给我提示,并通过以下CSS更改找到了解决方案,
i.fa {
background: #fff;
display: inline-block;
font-size: 80px;
transform: translateY(-60%);
transform: translateX(160%);
border-radius: 50%;
}
Adding this 'centericon' Class and css 添加此“ centericon”类和css
.centericon{
font-size:36px;
position:absolute;
top:-18px;
left:50%;
transform:translate(-50%,0);
z-index:99;
background:white;
}
.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; } .centericon{ font-size:36px; position:absolute; top:-18px; left:50%; transform:translate(-50%,0); z-index:99; background:white; }
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/> <div class="loginDiv"> <form> <div class="centericon"> <i class="fa fa-user-circle"></i> </div> <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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.