【发布时间】:2022-01-23 17:49:23
【问题描述】:
为什么网站不适合较小的设备? 还有一个水平滚动条。在设计视图中输入时,移动设备不会按照我想要的方式显示。我尝试调整所有内容的大小,但仍然无法正常工作。
它可能是某个地方的边距或填充吗?还是项目部分太大?还是与媒体查询有关?
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 110px auto 1fr 470px auto auto auto auto auto;
gap: 0px 0px;
grid-template-areas:
"header header header header"
"hero hero hero hero"
"about about about about"
"text text text text"
"project1 project1 project1 project1"
"project2 project2 project2 project2"
"project3 project3 project3 project3"
"project4 project4 project4 project4"
"footer footer footer footer";
}
@media (max-width: 1200px) {
.grid-container {
grid-template-columns: 1fr;
grid-template-rows: auto;
grid-template-areas:
"header"
"hero"
"about"
"text"
"project1"
"project2"
"project3"
"project4"
"footer";
}
}
@media only screen and (max-width: 1200px) {
section.content-container {
margin-left: 10px;
margin-right: 10px;
}
}
@media only screen and (max-width: 1200px) {
footer.content-container {
margin-left: 10px;
margin-right: 10px;
}
}
.header {
grid-area: header;
}
.navbar {
position: absolute;
display: inline-block;
top: 50px;
right: 60px;
font-family: 'Khula', sans-serif;
line-height: 38px;
font-weight: 400;
font-size: 16px;
}
.nav-link {
margin: 18px;
color: #222222;
text-decoration: none;
}
.name {
position: absolute;
display: inline-block;
top: 50px;
left: 60px;
font-family: 'Kanit', sans-serif;
line-height: 30px;
font-weight: 500;
font-size: 28px;
color: #222222;
text-decoration: none;
}
.hero {
grid-area: hero;
padding-top: 90px;
padding-bottom: 250px;
text-align: center;
}
.hero-h1 {
font-family: 'Khula', sans-serif;
font-weight: 600;
font-size: 100px;
color: #bbbbbb;
line-height: 100px;
letter-spacing: -1px;
}
.hero-h1-color {
color: #222222;
}
.container {
max-width: 1240px;
}
.about {
grid-area: about;
background-color: #f5f5f5;
height: 700px;
margin-left: 100px;
margin-right: 100px;
margin-top: 38px;
}
.home-h2-text {
font-family: 'Khula', sans-serif;
letter-spacing: -1px;
padding: 90px 100px 80px;
font-size: 70px;
color: #222222;
line-height: 70px;
}
.home-h3-text {
font-family: 'Khula', sans-serif;
letter-spacing: -1px;
font-size: 35px;
color: #222222;
padding: 90px 100px 80px;
font-weight: 400;
}
.text {
grid-area: text;
height: 500px;
margin-left: 100px;
margin-right: 100px;
font-family: 'Khula', sans-serif;
letter-spacing: -1px;
text-align: center;
font-size: 40px;
color: #bbbbbb;
padding-top: 138px;
line-height: 60px;
}
.text-h3-color {
color: #222222;
}
.project1 {
grid-area: project1;
background-color: #fdf0f2;
height: 700px;
margin-left: 100px;
margin-right: 100px;
margin-top: 38px;
}
.project2 {
grid-area: project2;
background-color: #f8f7ff;
height: 700px;
margin-left: 100px;
margin-right: 100px;
margin-top: 38px;
}
.project3 {
grid-area: project3;
background-color: #fdf0f2;
height: 700px;
margin-left: 100px;
margin-right: 100px;
margin-top: 38px;
}
.project4 {
grid-area: project4;
background-color: #eff5fd;
height: 700px;
margin-left: 100px;
margin-right: 100px;
margin-top: 38px;
}
.footer {
grid-area: footer;
margin-top: 38px;
margin-left: 100px;
margin-right: 100px;
height: 700px;
margin-bottom: 100px;
}
.footer-text {
padding: 200px 100px;
font-family: 'Khula', sans-serif;
font-weight: 600;
font-size: 80px;
color: #bbbbbb;
line-height: 80px;
letter-spacing: -1px;
}
.footer-contact {
font-family: 'Khula', sans-serif;
font-weight: 600;
font-size: 35px;
color: #222222;
line-height: 50px;
letter-spacing: -1px;
text-decoration: none;
padding-top: 0px;
margin-left: 60px;
margin-right: 60px;
}
.footer-text-color {
color: #222222;
}
ul {
list-style-type: none;
text-decoration: none;
}
<div class="grid-container">
<header class="header">
<div><a href=index.html class="name">Web Developer</a></div>
<nav class="navbar">
<a href=about.html class="nav-link">About</a>
<a href=projects.html class="nav-link">Projects</a>
<a href=contact.html class="nav-link">Contact</a>
</nav>
</header>
<div class="hero">
<h1 class="hero-h1">ABC <br /><span class="hero-h1-color">front end developer</span></h1>
</div>
<section class="content-container about">
<h2 class="home-h2-text">Nice to <br />meet you</h2>
<h3 class="home-h3-text">About Me</h3>
</section>
<div class="content-container text">
<h3>ABCDEFG <br /><span class="text-h3-color">ABCDEFG.</span></h3>
</div>
<section class="content-container project1">
<h2 class="home-h2-text">Project 1</h2>
<h3 class="home-h3-text">About Me</h3>
</section>
<section class="content-container project2">
<h2 class="home-h2-text">Project 2</h2>
<h3 class="home-h3-text">About Me</h3>
</section>
<section class="content-container project3">
<h2 class="home-h2-text">Project 3</h2>
<h3 class="home-h3-text">About Me</h3>
</section>
<section class="content-container project4">
<h2 class="home-h2-text">Project 4</h2>
<h3 class="home-h3-text">About Me</h3>
</section>
<footer class="content-container footer">
<div class="footer-text">Let's <br> <span class="footer-text-color">Connect</span></div>
<ul>
<li><a href=about.html class="footer-contact">Email</a></li>
<li><a href=projects.html class="footer-contact">LinkedIn</a></li>
<li><a href=contact.html class="footer-contact">GitHub</a></li>
</ul>
</footer>
</div>
【问题讨论】:
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">已经在你的脑海里了吗? -
根据页面当前的使用方式,您可以通过使用 flexbox 大大简化 css。您当前使用网格的方式(例如,请参阅
grid-template-areas)并没有真正的帮助,并且出于某种原因您正在对标题标题使用绝对定位?别误会,grid是个好东西,但你的网站根本不代表一个网格,它只是一个一维布局;一列行(display:flex更适合)。您可以将标题本身设置为 flexbox,也可以包含 2 列(1 列用于标题,1 列用于导航) -
@Kameron 我没有元名称视口标签,但包含它们并且它仍然相同。我想抑制移动视图上的水平滚动,但不知道怎么做?
-
@user8 查看已编辑的答案以防止水平滚动。