我目前正在制作onesie滚动网站,但是我遇到了这个问题。我希望我的文字位于第一个“页面”的中心,但我无法使其同时在手机和台式机上看起来不错。 使用padding-top:50%的手机看起来不错,但在台式机上却很糟糕;另一方面,padding-top:7的手机在台式机上看起来不错,但在手机上却不多。有人可以帮助我找到中庸之道吗?
我的html代码:
section {
width: 100%;
height: 100vh;
}
.main section.page1 {
background: #81D4FA;
}
.main section.page2 {
background: #F5F5F5;
}
.main section.page3 {
background: #81D4FA;
}
h1 {
font-size: 8vw;
color: #efefef;
text-align: top;
padding-top: 50%;
padding-left: 15%;
}
h2
{
list-style-type: none;
font-size: 4vw;
color: #efefef;
text-align: center;
padding-top: 2%;
}
a.read-more{
border: 2px solid #efefef;
text-decoration: none;
color: inherit;
}
.notnav {
list-style-type: none;
font-size: 3vw;
padding-top: 2%;
padding-left: 5%;
padding-right: 15%;
}
<div class="main">
<section class="page1">
<h1>
ABOUT ME
<li class="notnav">
I am John, 19 years old computer science student. Mainly coding in python, but I am quick lerner and flexible person. I am currently intrested in Artificial Intelligence, Big Data and Design
</li>
</h1>
<h2>
<a class="read-more" href='/about'>Read More</a>
</h2>
</section>
<section class="page2">
<h1>
PROJECTS
</h1>
</section>
<section class="page3">
<h1>
CONTACT
</h1>
</section>
</div>
答案 0 :(得分:2)
尝试一下(不使用媒体查询);晚会很抱歉
section {
width: 100%;
height: 100vh;
}
.main section.page1 {
background: #81D4FA;
}
.main section.page2 {
background: #F5F5F5;
}
.main section.page3 {
background: #81D4FA;
}
.page1{
display:flex;
min-height: 100%;
align-items: center;
text-align: center;
flex-direction: column;
justify-content:center;
}
h1 {
font-size: 8vw;
color: #efefef;
}
h2
{
list-style-type: none;
font-size: 4vw;
color: #efefef;
text-align: center;
}
a.read-more{
border: 2px solid #efefef;
text-decoration: none;
color: inherit;
}
.notnav {
list-style-type: none;
font-size: 3vw;
clear: both;
}
答案 1 :(得分:1)
根据您的代码,下面是通过媒体查询对section.page1
进行改编的示例。这就是您应该用来使代码适应和响应的方式。
@media screen and (min-width: 400px){
section {
width: auto;
height: auto;
}
section.page1{
padding: 20px;
}
h1 {
font-size: 8vw;
color: #efefef;
text-align: top;
padding-top: 10px;
padding-left: 15%;
}
}
这里有一个很大的说明:Mozilla Developper Using_media_queries
获得更多练习和示例您还可以使用引导程序通过其网格系统来获得简单的CSS:Bootstrap Grid
section {
width: 100%;
height: 100vh;
}
.main section.page1 {
background: #81D4FA;
}
.main section.page2 {
background: #F5F5F5;
}
.main section.page3 {
background: #81D4FA;
}
h1 {
font-size: 8vw;
color: #efefef;
text-align: top;
padding-top: 50%;
padding-left: 15%;
}
h2
{
list-style-type: none;
font-size: 4vw;
color: #efefef;
text-align: center;
padding-top: 2%;
}
a.read-more{
border: 2px solid #efefef;
text-decoration: none;
color: inherit;
}
.notnav {
list-style-type: none;
font-size: 3vw;
padding-top: 2%;
padding-left: 5%;
padding-right: 15%;
}
@media screen and (min-width: 400px){
section {
width: auto;
height: auto;
}
section.page1{
padding: 20px;
}
h1 {
font-size: 8vw;
color: #efefef;
text-align: top;
padding-top: 10px;
padding-left: 15%;
}
}
<div class="main">
<section class="page1">
<h1>
ABOUT ME
</h1>
<div class="notnav">
I am John, 19 years old computer science student. Mainly coding in python, but I am quick lerner and flexible person. I am currently intrested in Artificial Intelligence, Big Data and Design
</div>
<h2>
<a class="read-more" href='/about'>Read More</a>
</h2>
</section>
<section class="page2">
<h1>
PROJECTS
</h1>
</section>
<section class="page3">
<h1>
CONTACT
</h1>
</section>
</div>