Как сделать так, чтобы шрифт появился в центре внутри div? - PullRequest
0 голосов
/ 25 апреля 2018

Я погуглил вышеупомянутую проблему, но мне все еще нужна помощь сообщества переполнения стека.

В своей форме входа в систему я использую значок шрифта awesome.У меня есть 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%;
    }

Вывод, который я получаю, выглядит следующим образом:

enter image description here

Но я хочу, чтобы значок появлялся прямо над вводом имени пользователя и в центре.Пожалуйста, помогите мне.

Ответы [ 3 ]

0 голосов
/ 25 апреля 2018

Спасибо, что дали мне подсказку и нашли решение со следующими изменениями в css,

i.fa {
    background: #fff;
    display: inline-block;
    font-size: 80px;
    transform: translateY(-60%);
    transform: translateX(160%);
    border-radius: 50%;
    }
0 голосов
/ 25 апреля 2018

Добавление этого класса '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>
0 голосов
/ 25 апреля 2018

Попробуйте добавить строку над контейнером,

<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>
...