html - 为什么在响应模式下调整大小时我的网站被推到左侧?
问题描述
我已将此网站作为我自己的练习组合网站,当我的网站小于特定大小时,我的网站就会被推到左侧。它曾经是大约 600 像素,但我删除了整个代码并再次重写了网站,但我在早期阶段检查了它,仍然遇到这个问题,我找不到它的原因。所以我停止了编码,直接来这里寻求帮助。请帮助我这是我第三次尝试建立这个网站但仍然遇到这个问题。我注意到的另一件事是,尽管我隐藏了滚动 x,但在调整网站大小时,我仍然有这个小滚动。在此处输入图像描述
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
overflow: visible;
overflow-x: hidden;
margin: 0;
padding: 0;
box-sizing: border-box;
}
p {
color: rgb(218, 214, 214);
font-family: "Montserrat", sans-serif;
font-size: 1rem;
}
/*NAVBAR----------------------------------------------------------------------------------------*/
.navbar {
width: 100vw;
height: auto;
font-family: "Poppins", sans-serif;
font-weight: 500;
padding: 7px;
background-color: rgba(85, 85, 85, 0.116);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
.icon-list {
display: flex;
justify-content: center;
align-items: center;
list-style: none;
}
.icon-list li {
text-align: center;
margin: 0 15px;
}
.icon-list a {
text-decoration: none;
color: rgb(180, 148, 158);
}
.icon-list a:hover {
opacity: 0.7;
}
.images {
width: 40px;
height: 40px;
}
/*INFO---------------------------------------------------------------------------------*/
.info {
font-family: "Montserrat", sans-serif;
margin-bottom: 200px;
padding: 100px;
text-align: center;
}
.info p {
margin: 0 40px;
line-height: 20px;
}
.info h1 {
font-weight: 600;
color: rgb(177, 164, 164);
font-weight: 300;
margin-bottom: 5px;
}
.info h2 {
color: rgb(192, 184, 153);
font-weight: 400;
}
.info h3 {
color: crimson;
font-weight: 500;
margin-top: 30px;
margin-bottom: 10px;
}
.shadow {
width: 80vw;
background-color: rgba(34, 33, 33, 0.336);
padding: 10px;
border-radius: 10px;
margin: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,300;0,600;0,700;0,800;1,300;1,400;1,500&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link rel="preconnect" href="https://fonts.gstatic.com">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ashkan Naeimipoor</title>
</head>
<link rel="stylesheet" href="./main.css">
<body>
<nav class="navbar">
<ul class="icon-list">
<li><a href=""><img class="images" src="./images/navbar/home.png" alt=""><br>HOME</a></li>
<li><a href=""><img class="images" src="./images/navbar/resume.png" alt=""><br>GET RESUME</a></li>
<li><a href=""><img class="images" src="./images/navbar/about.png" alt=""><br>ABOUT</a></li>
<li><a href=""><img class="images" src="./images/navbar/contact-book.png" alt=""><br>CONTACT</a></li>
</ul>
</nav>
<div class="container">
<div class="info">
<div class="shadow">
<h1>Ashkan Naeimipoor</h1>
<h2>Front-End Developer</h2>
<h3>Objective</h3>
<p>As a Front-End Developer, to be responsible for
producing high quality solutions for company customers; bringing growing understanding of Modern HTML, JavaScript, and CSS, and passionate ability to learn and develope
while working in the team of experts under a
skillful and talented management.</p>
</div>
</div>
</div>
</body>
</html>
解决方案
检查您的 .info 类,您在填充上使用 100px。这在较小的屏幕上太大了。您可以使用媒体查询来减少它。
我还建议将 .info 类更改为:
.info {
font-family: "Montserrat", sans-serif;
margin-bottom: 200px;
padding: 100px 0;
text-align: center;
max-width: 1060px;
margin: 0 auto;
}
推荐阅读
- reactjs - react.js 超过最大更新深度
- pine-script - 在图表上显示更高的时间范围指标
- mysql - 如果有来自另一个表的空值,如何填充(与其他表连接)?
- javascript - 如何在 d3 中为可视化创建一个函数而不是 3 个或更多函数,然后在悬停在节点上时添加突出显示
- java - 未检测到 JavaFX
- spring-boot - 多个 Gradle bootJar 配置 - 不同的 mainClass 属性?
- javascript - 重构 += 表达式
- rust - 在 Rust 中使用输入初始化全局变量
- pandas - 如何为从另一个数据框创建的变量获取 1/0 值(按条件)?(熊猫/numpy)
- django - django视图中的django,jwt身份验证,而不仅仅是DRF