网格列重叠
Grid columns are overlapping
我是一名练习网格和响应式设计的初学者。我将 600px 作为断点,但当我调整屏幕大小时,我的 .main div 中的列只是重叠,带有社交媒体图标的页脚不会位于中心。在 codepen 上:https://codepen.io/charity-temple/pen/gOPvJbz
HTML:
<div class="container">
<header>
<h1>LOGO</h1>
</header>
<main>
<div class="main_imageholder">
<img src="https://res.cloudinary.com/du07lnlg2/image/upload/v1594091023/Messaging_fun-amico_1_mg8xyo.png" alt="sitting-girl">
</div>
<div class="textholder">
<h1>Lead with the possibility to surprise and delight</h1>
<p>Take stakeholder management so that as an end result, we improve overall outcomes. Repurpose cloud computing and finally make users into advocates.</p>
<button href="#">Register</button>
</div>
</main>
<div class="social">
<ul>
<li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
<li><a href="#"><i class="fab fa-twitter"></i></a></li>
<li><a href="#"><i class="fab fa-instagram"></i></a></li>
</ul>
</div>
</div>
CSS:
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: #34495e;
}
.container{
border: solid white;
width:auto;
margin: auto;
color: white;
display: grid;
}
header{
border: solid red;
width:90%;
margin-top: 40px;
margin-right: auto;
margin-left: auto;
display: grid;
align-items: center;
}
header > h1{
font-weight: 900px;
font-size: 3vw;
}
main {
border:solid blue;
width: 90%;
height: auto;
margin:auto;
display: grid;
grid-template-columns: 1fr 1fr;
grid-column-gap:10px;
}
.main_imageholder{
border:solid yellow;
padding: 40px;
}
.main_imageholder > img{
width: 100%;
}
.textholder{
border: solid pink;
padding: 30px;
}
h1{
font-family: "Poppins";
font-weight: 500;
font-size: 32px;
}
p{
font-family: "Open Sans";
font-weight: 400;
font-size: 15px;
line-height: 24px;
margin-top: 20px;
}
button{
margin-top:20px;
font-family: "Poppins";
font-size: 12px;
font-weight: 300;
width: 90px;
padding: 5px;
height: auto;
color: #34495e;
text-decoration: none;
background-color: white;
border: 0px;
border-radius: 50px;
}
button:hover{
background-color: #2c3e50;
color: #fff;
cursor: pointer;
}
.social{
border: solid orange;
width: 90%;
margin: 0px auto auto auto;
display: flex;
justify-content: flex-end;
}
.social ul{
display:flex;
}
.social > ul > li{
list-style: none;
border: 1px white solid;
border-radius: 100%;
width: 30px;
height: 30px;
margin-left: 1vw;
display:flex;
justify-content:center;
align-items: center;
}
.social > ul > li > a{
font-size: 12px;
color: #fff;
}
@media screen and (max-width: 600px) {
.main_imageholder{grid-area: main_imageholder;}
.textholder{grid-area: textholder;}
.main{
grid-template-areas:
'main_imageholder main_imageholder'
'textholder textholder'
}
.social{
justify-content: center;
}
}
您在第一位指定类型选择器(节点类型 'main'),并在媒体查询中指定 class 类型选择器(节点 class 为 'main').这只是一个错字。删除媒体查询 css.
中 'main' 之前的句点
例如:
@media screen and (max-width: 600px) {
.main_imageholder{grid-area: main_imageholder;}
.textholder{grid-area: textholder;}
main{
grid-template-areas:
'main_imageholder main_imageholder'
'textholder textholder'
}
.social{
justify-content: center;
}
}
我是一名练习网格和响应式设计的初学者。我将 600px 作为断点,但当我调整屏幕大小时,我的 .main div 中的列只是重叠,带有社交媒体图标的页脚不会位于中心。在 codepen 上:https://codepen.io/charity-temple/pen/gOPvJbz
HTML:
<div class="container">
<header>
<h1>LOGO</h1>
</header>
<main>
<div class="main_imageholder">
<img src="https://res.cloudinary.com/du07lnlg2/image/upload/v1594091023/Messaging_fun-amico_1_mg8xyo.png" alt="sitting-girl">
</div>
<div class="textholder">
<h1>Lead with the possibility to surprise and delight</h1>
<p>Take stakeholder management so that as an end result, we improve overall outcomes. Repurpose cloud computing and finally make users into advocates.</p>
<button href="#">Register</button>
</div>
</main>
<div class="social">
<ul>
<li><a href="#"><i class="fab fa-facebook-f"></i></a></li>
<li><a href="#"><i class="fab fa-twitter"></i></a></li>
<li><a href="#"><i class="fab fa-instagram"></i></a></li>
</ul>
</div>
</div>
CSS:
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: #34495e;
}
.container{
border: solid white;
width:auto;
margin: auto;
color: white;
display: grid;
}
header{
border: solid red;
width:90%;
margin-top: 40px;
margin-right: auto;
margin-left: auto;
display: grid;
align-items: center;
}
header > h1{
font-weight: 900px;
font-size: 3vw;
}
main {
border:solid blue;
width: 90%;
height: auto;
margin:auto;
display: grid;
grid-template-columns: 1fr 1fr;
grid-column-gap:10px;
}
.main_imageholder{
border:solid yellow;
padding: 40px;
}
.main_imageholder > img{
width: 100%;
}
.textholder{
border: solid pink;
padding: 30px;
}
h1{
font-family: "Poppins";
font-weight: 500;
font-size: 32px;
}
p{
font-family: "Open Sans";
font-weight: 400;
font-size: 15px;
line-height: 24px;
margin-top: 20px;
}
button{
margin-top:20px;
font-family: "Poppins";
font-size: 12px;
font-weight: 300;
width: 90px;
padding: 5px;
height: auto;
color: #34495e;
text-decoration: none;
background-color: white;
border: 0px;
border-radius: 50px;
}
button:hover{
background-color: #2c3e50;
color: #fff;
cursor: pointer;
}
.social{
border: solid orange;
width: 90%;
margin: 0px auto auto auto;
display: flex;
justify-content: flex-end;
}
.social ul{
display:flex;
}
.social > ul > li{
list-style: none;
border: 1px white solid;
border-radius: 100%;
width: 30px;
height: 30px;
margin-left: 1vw;
display:flex;
justify-content:center;
align-items: center;
}
.social > ul > li > a{
font-size: 12px;
color: #fff;
}
@media screen and (max-width: 600px) {
.main_imageholder{grid-area: main_imageholder;}
.textholder{grid-area: textholder;}
.main{
grid-template-areas:
'main_imageholder main_imageholder'
'textholder textholder'
}
.social{
justify-content: center;
}
}
您在第一位指定类型选择器(节点类型 'main'),并在媒体查询中指定 class 类型选择器(节点 class 为 'main').这只是一个错字。删除媒体查询 css.
中 'main' 之前的句点例如:
@media screen and (max-width: 600px) {
.main_imageholder{grid-area: main_imageholder;}
.textholder{grid-area: textholder;}
main{
grid-template-areas:
'main_imageholder main_imageholder'
'textholder textholder'
}
.social{
justify-content: center;
}
}