【问题标题】:Top part of my website disappears when I resize it vertically垂直调整大小时,网站的顶部消失了
【发布时间】:2020-02-16 01:27:03
【问题描述】:

我正在尝试为一所大学创建一个响应式登录页面,但是当我垂直调整窗口大小时,徽标和顶部基本上消失了。

目前我正在使用 Google Chrome 中的开发工具为 iPhone 7 进行设计,以帮助我查看视图。当我在华为手机上打开网站并点击密码字段时,键盘会将页面向上推,徽标部分消失。这不会发生在我的 iPhone 上。

我认为问题出在我的 div 元素中。对不起,如果这是一个愚蠢的问题,我是初学者。

网址:https://borislav1333.000webhostapp.com/

body
{
	margin: 0;
}

img
{
	max-width: 300px;
	position: absolute;
	top: 60px;
	left: 37px;
	z-index: 1;

}

.container
{
	width: 375px;
	height: 667px;
	background-color: white;
	margin: auto;
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	font-family: Georgia;
}

.form-back
{
	width: 200px;
	background-color: white;
	z-index: 1;
	margin: 0 auto;
	padding: 45px;
	position: absolute;
	top: 80%;
	left: 50%;
	transform: translate(-50%, -80%);
	text-align: center;
	font-size: 18px;
}


input[type=text], input[type=password]
{
	width: 100%;
	padding: 10px;
	margin: 8px 0px 8px;
	border: solid 1px #aaa;	
	border-radius: 4px;
}

button
{
	width: 100%;
	height: 50px;
	border: none;
	border-radius: 30px;
	border-color: white;
	background-color: #e52791;
	font-family: Georgia;
	transition: background-color 0.7s ease-out;
}

button:hover
{
	background-color: #02356a;
	color: white;
	transition: background-color 0.7s ease;
}

.submit
{
	position: relative;
	top: 30px;
}

::placeholder
{
	font-family: georgia;
}
<div class="container">
	<div class="img"><img src="logo.jpg"></div>

	<div class="form-back">
		<form action="message.html" onsubmit="return validation()">
				<div>
					<label for="accountNum">Metric Number</label><br>
					<input type="text" id="accountNum" name="accountNum" placeholder="Metric Number..."><br>
				</div>

				<div>
					<label for="surname">Password:</label><br>
					<input type="password" id="surname" name="surname" placeholder="Password..."><br>
				</div>

				<div class="submit">
					<button type="submit">Log In</button>
				</div>
	</div>
</div>

【问题讨论】:

    标签: css


    【解决方案1】:

    根据您的代码,您在许多元素中使用了位置绝对值。我认为你所面临的这个问题是由于这个绝对而发生的。我已经更新了你的 CSS 代码并在下面添加了 sn-p。更换它并检查,希望您的问题得到解决:

             body
              {
                  margin: 0;
              }
    
              img
              {
                  width: 100%;
                  max-width: 300px;
                  z-index: 1;
                  margin: 0 auto;
              }
    
              .container
              {
                  margin: 0 auto;
                  font-family: Georgia;
                  text-align: center;
              }
    
              .form-back
              {
                  width: 100%;
                  
                  background:transparent;
                  margin: 0 auto;
                  padding: 45px;
                  text-align: center;
                  font-size: 18px;
              }
    
    
              input[type=text], input[type=password]
              {
                  width: 100%;
                  padding: 10px;
                  margin: 8px 0px 8px;
                  border: solid 1px #aaa; 
                  border-radius: 4px;
              }
    
              button
              {
                  width: 100%;
                  height: 50px;
                  border: none;
                  border-radius: 30px;
                  border-color: white;
                  background-color: #e52791;
                  font-family: Georgia;
                  transition: background-color 0.7s ease-out;
              }
    
              button:hover
              {
                  background-color: #02356a;
                  color: white;
                  transition: background-color 0.7s ease;
              }
    
              .submit
              {
                  position: relative;
                  top: 30px;
              }
    
              ::placeholder
              {
                  font-family: georgia;
              }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    
    <div class="container">
        <div class="img"><img src="https://borislav1333.000webhostapp.com/logo.jpg"></div>
    
        <div class="form-back">
            <form action="message.html" onsubmit="return validation()">
                    <div>
                        <label for="accountNum">Metric Number</label><br>
                        <input type="text" id="accountNum" name="accountNum" placeholder="Metric Number..."><br>
                    </div>
    
                    <div>
                        <label for="surname">Password:</label><br>
                        <input type="password" id="surname" name="surname" placeholder="Password..."><br>
                    </div>
    
                    <div class="submit">
                        <button type="submit">Log In</button>
                    </div>
                  </form>
        </div>
    </div>

    【讨论】:

    • 是的,解决了页面顶部消失的问题,但是当我进入移动模式时,img、input 和按钮未居中对齐。 ibb.co/ykR6Mn2
    • 这很有趣。我用相同的浏览器设置(iphone 6/7/8)检查了我的 sn-p。它在我的笔记本电脑上运行良好。我不确定确切的问题是什么。您是否在 HTML 的标头中添加了引导 CDN 链接。可能就是这个问题。我正在添加使用引导 CDN url 更新我的 sn-p。请检查。
    • 大家好,是的,这是正确的。 HTML 的头部缺少 Bootstrap CND 链接。我已经更新了我的 sn-p。请使用它。
    • 哇,感谢您的快速修复!你能给我推荐一个视频或解释那行代码是如何解决这个问题的吗?
    • 是的,请查看此视频了解更多信息:link
    猜你喜欢
    • 1970-01-01
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多