Макет веб-страницы на разных экранах по-разному - PullRequest
0 голосов
/ 25 апреля 2018

Я разработал свою веб-страницу,

HTML-код,

<div class="firstDiv"></div>
<div class="secondDiv"></div>
<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>
      <br/>
      <br/>
    <button mat-button (click)="submit()">Login</button>
    <br/>
    <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: 60%;
    height: 20%;
    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;
    display: block;
    margin: auto;
    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;
    font-size: 80px;
    transform: translateY(-60%);
    transform: translateX(160%);
    border-radius: 50%;
    margin: auto;
    position: relative;
    }

И когда я запускаю веб-страницу, я получаю разные представления,

1) Для настольного браузера

enter image description here

2) Для небольших экранов, таких как IPhone 6

enter image description here

3) Для Ipad Pro,

enter image description here

Я хотел, чтобы значок пользователя отображался в центре, но он отклоняется от центра в зависимости от размеров экрана.

Ответы [ 3 ]

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

Использование flexbox для строки, содержащей круг.Документация в источнике.

/* Added display flex for circle row */

div.row.center {
  display: flex;
  justify-content: center;
  width: 100%;
}

.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: 60%;
  height: 20%;
  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;
  display: block;
  margin: auto;
  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;
  font-size: 80px;
  /* transform: translateY(-60%); removed */
  /* transform: translateX(160%); removed */
  border-radius: 50%;
  /* margin: auto; removed */
  /* position: relative; removed */
}
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<div class="firstDiv"></div>
<div class="secondDiv"></div>
<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>
      <br/>
      <br/>
      <button mat-button (click)="submit()">Login</button>
      <br/>
      <label>
      <input type="checkbox" checked="checked" name="remember"> Remember me
    </label>
    </div>
  </form>
</div>
0 голосов
/ 25 апреля 2018

Очень легко исправить.

По какой-то причине у вас есть преобразования в вашем круге, см. Код:

i.fa {
background: #fff;
display: inline-block;
font-size: 80px;
/* transform: translateY(-60%); */
/* transform: translateX(160%); */
border-radius: 50%;
margin: auto;
position: relative;
}

Удалите эти две закомментированные строки, а затем добавьте следующий CSS:

.center {
    text-align: center;
}
0 голосов
/ 25 апреля 2018

попробуйте это для вашего круга div

position: absolute;
left: 0;
right: 0;
margin: auto;
...