自适应网页设计中的自动高度问题

时间:2018-08-30 18:24:10

标签: html css

我正在制作一个响应式登录页面,并且我正确完成了所有操作,这是我的html代码

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: #c6faff;
  font-family: Segoe WP Black;
}
.form-box {
  position: absolute;
  width: 715px;
  height: auto;
  min-height: 400px;
  background-image: linear-gradient(to right top, #051937, #10325f, #184f8b, #1b6dba, #128deb);
  opacity: .8;
  left: 50%;
  bottom: 50%;
  transform: translate(-50%, 50%);
  border-radius: 5px;
  color: black;

}
.form-left-side {
  position: relative;
  float: left;
  width: 50%;
  max-width: 337px;
  background-color: #fff1ff;
  height: 100%;
  min-height: 400px;
  padding: 7px;
  border: 3px solid black;
  color: black;
}
.form-right-side {
  position: relative;
  float: left;
  width: 50%;
  max-width: 337px;
  height: 100%;
  padding-left: 15px;
  min-height: 400px;
  background-color: #fff1ff;
  padding: 7px;
  border: 3px solid black;
  border-left: none;
  color: black;
  padding-left: 10px;
}
.text-field {
  margin-top: 20px;
  border: none;
  outline: none;
  opacity: .9;
  padding: 7px;
  background: none;
  border-bottom: 2px solid #2196F3;
  transition: .5s;
}
.submit {
  background-image: linear-gradient(to right, #ed00af, #f81795, #fc327f, #fb496c, #f65e5e);
  color: white;
  padding: 7px;
  width: 160px;
  height: 50px;
  font-size: 15px;
  border: 2px solid grey;
  font-weight: bold;
  font-family: Segoe WP Black;
  cursor: pointer;
  transition: .7s;
  outline: none;
  border-radius: 20px 0px 20px 0px;
}
.text-field:focus {
  padding: 8px;
  border-bottom: 3px solid black;
  font-size: 16px;
}
.submit:hover {
  border-radius: 0px 20px 0px 20px;
  box-shadow: 5px 10px 20px rgb(0, 0, 0, .3);
  width: 170px;
  height: 60px;
  transition: .7s;
}
.text-field::placeholder {
  color: black;
  opacity: 1; /* Firefox */
  font-size: 13px;
}

.text-field:-ms-input-placeholder { /* Internet Explorer 10-11 */
  color: red;
  opacity: .8; /* Firefox */
  font-size: 13px;
}

.text-field::-ms-input-placeholder { /* Microsoft Edge */
  color: red;
  opacity: .8; /* Firefox */
  font-size: 13px;
}
@media screen and (max-width: 730px) {
  .form-box {
    width: 100%;
    height: auto;
    min-height: 0;
    left: 0;
    bottom: 0;
    transform: translate(-0, 0);
  }
  .form-left-side {
    position: relative;
    width: 97.1%;
    float: none;
    display: block;
    max-width: none;
    min-height: 300px;
    height: auto;
    text-align: center;
  }
  .form-right-side {
    position: relative;
    width: 96.7%;
    float: none;
    display: block;
    border-left: 3px solid black;
    max-width: none;
  }
  .text-field {
    width: 70%;
  }
}
        <html>
        <head>
          <title>Form</title>
          <link rel="stylesheet" type="text/css" href="style.css">
          <meta name="viewport" content="width=device-width, intital-scale=1">
        </head>
        <body>
          <div class="form-box">
            <div class="form-left-side">
              <center><h2 style="font-size:20px;">Register For Best Performance</h2>
              <p>When You Register at This Site You Can Use Our Features
                 And Have The Best Performance Here Thank You For Joining Us!<br>
              Never Foget This You Can Do Anything at This Site And
               This is For Everyone And We Won't do Building a Website For Just Somebody !
              </p>
              </center>
            </div>
            <div class="form-right-side">
              <h2>Login</h2>
              <form>
                <label for="fname">Username: </label><br><center>
                <input type="text" name="fname" value="" class="text-field" placeholder="Username" />
                <br /><br /><br></center>
                <label for="fname">Password: </label>
                <br /><center>
                <input type="password" name="password" value="" class="text-field" placeholder="Password" />
                <br><br><br></center>
                <center><input type="submit" name="submit" value="Submit" class="submit">
                  <br></center>
              </form>
            </div>
          </div>
        </body>
        </html>

当我将屏幕尺寸缩小到730像素时,可以正常工作,但是我在窗体左侧的文本上升了,没有东西可以滚动并且我的文本的第一行不可见 请注意,我不想降低我的最低身高,如果您能帮助我,我希望它是300像素

,并且在此站点上的代码段上运行时也请注意,您无法向上滚动,因此存在问题 我的浏览器是歌剧

1 个答案:

答案 0 :(得分:0)

发生您的问题是因为您绝对是从页面底部开始放置,将其更改为顶部可以解决此问题。 :) 您也可以将position: relative添加到媒体查询中,以确保它不会超出屏幕。 :)

body {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  background-color: #c6faff;
  font-family: Segoe WP Black;
}
.form-box {
  position: absolute;
  width: 715px;
  height: auto;
  min-height: 400px;
  background-image: linear-gradient(to right top, #051937, #10325f, #184f8b, #1b6dba, #128deb);
  opacity: .8;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 5px;
  color: black;

}
.form-left-side {
  position: relative;
  float: left;
  width: 50%;
  max-width: 337px;
  background-color: #fff1ff;
  height: 100%;
  min-height: 400px;
  padding: 7px;
  border: 3px solid black;
  color: black;
}
.form-right-side {
  position: relative;
  float: left;
  width: 50%;
  max-width: 337px;
  height: 100%;
  padding-left: 15px;
  min-height: 400px;
  background-color: #fff1ff;
  padding: 7px;
  border: 3px solid black;
  border-left: none;
  color: black;
  padding-left: 10px;
}
.text-field {
  margin-top: 20px;
  border: none;
  outline: none;
  opacity: .9;
  padding: 7px;
  background: none;
  border-bottom: 2px solid #2196F3;
  transition: .5s;
}
.submit {
  background-image: linear-gradient(to right, #ed00af, #f81795, #fc327f, #fb496c, #f65e5e);
  color: white;
  padding: 7px;
  width: 160px;
  height: 50px;
  font-size: 15px;
  border: 2px solid grey;
  font-weight: bold;
  font-family: Segoe WP Black;
  cursor: pointer;
  transition: .7s;
  outline: none;
  border-radius: 20px 0px 20px 0px;
}
.text-field:focus {
  padding: 8px;
  border-bottom: 3px solid black;
  font-size: 16px;
}
.submit:hover {
  border-radius: 0px 20px 0px 20px;
  box-shadow: 5px 10px 20px rgb(0, 0, 0, .3);
  width: 170px;
  height: 60px;
  transition: .7s;
}
.text-field::placeholder {
  color: black;
  opacity: 1; /* Firefox */
  font-size: 13px;
}

.text-field:-ms-input-placeholder { /* Internet Explorer 10-11 */
  color: red;
  opacity: .8; /* Firefox */
  font-size: 13px;
}

.text-field::-ms-input-placeholder { /* Microsoft Edge */
  color: red;
  opacity: .8; /* Firefox */
  font-size: 13px;
}
@media screen and (max-width: 730px) {
  .form-box {
    width: 100%;
    height: auto;
    min-height: 0;
    left: 0;
    top: 0;
    transform: translate(0, 0);
    position: relative;
  }
  .form-left-side {
    position: relative;
    width: 97.1%;
    float: none;
    display: block;
    max-width: none;
    min-height: 300px;
    height: auto;
    text-align: center;
  }
  .form-right-side {
    position: relative;
    width: 96.7%;
    float: none;
    display: block;
    border-left: 3px solid black;
    max-width: none;
  }
  .text-field {
    width: 70%;
  }
}
<html>
<head>
  <title>Form</title>
  <link rel="stylesheet" type="text/css" href="style.css">
  <meta name="viewport" content="width=device-width, intital-scale=1">
</head>
<body>
  <div class="form-box">
    <div class="form-left-side">
      <center><h2 style="font-size:20px;">Register For Best Performance</h2>
      <p>When You Register at This Site You Can Use Our Features
         And Have The Best Performance Here Thank You For Joining Us!<br>
      Never Foget This You Can Do Anything at This Site And
       This is For Everyone And We Won't do Building a Website For Just Somebody !
      </p>
      </center>
    </div>
    <div class="form-right-side">
      <h2>Login</h2>
      <form>
        <label for="fname">Username: </label><br><center>
        <input type="text" name="fname" value="" class="text-field" placeholder="Username" />
        <br /><br /><br></center>
        <label for="fname">Password: </label>
        <br /><center>
        <input type="password" name="password" value="" class="text-field" placeholder="Password" />
        <br><br><br></center>
        <center><input type="submit" name="submit" value="Submit" class="submit">
          <br></center>
      </form>
    </div>
  </div>
</body>
</html>