html - 如何防止 div 的位置在调整屏幕大小时发生变化
问题描述
我有这个代码
<div id="PageContainer">
<main>
<section id="section1">
<div id="section1width">
<div id="section1Content">
<p id="logo">Logo</p>
<h1 id="h1Section1">Start tracking your life with MementoMori</h1>
<p id="pSection1">Improves life check</p>
<div id="buttonCenterSection1">
<button>Try it</button>
</div>
<div id="bigTextSection1Container">
<div id="bigTextSection1">
<p id="pSection1"> Try mementomori now, and start lorem impusm lorem impusmlorem impusmlorem impusmlorem impusmlorem impusmlorem impusmlorem impusmlorem impusmlorem impusm</p>
</div>
</div>
<div id="imgContainerSection1">
<img id="imgSection1" src="https://images.unsplash.com/photo-1508138221679-760a23a2285b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&w=1000&q=80"></img>
</div>
</div>
</div>
</section>
<section id="section2"></section>
</main>
</div>
而这个CSS
*{
margin: 0;
padding:0;
box-sizing: border-box;
}
#section1{
height:100vh;
background-color: blue;
display:flex;
justify-content: center;
}
#section1width{
width:60%;
height:80%;
background-color:purple;
display:flex;
justify-content:center;
}
#section1Content{
width:80%;
}
#logo{
text-align:center;
}
#h1Section1{
text-align:center;
}
#pSection1{
text-align:center;
}
#buttonCenterSection1{
display:flex;
justify-content: center;
}
#bigTextSection1Container{
display:flex;
justify-content: center;
}
#bigTextSection1{
width:50%;
}
#imgContainerSection1{
display:flex;
justify-content:center;
}
#imgSection1{
width:75%;
height:75%;
}
#section2{
height:100vh;
background-color:red;
}
我面临的问题如下
我试图将红色框移动到黄色位置。我用 magrin-top: 15vh 做到了,但问题是它没有响应,如果我改变屏幕尺寸,一切都会再次混乱。
如何在屏幕调整大小时在顶部应用边距而不弄乱结构?
解决方案
推荐阅读
- node.js - MongoDB Stitch - 如何在更新时将数据类型保持为 int(不更改为 double)?
- c# - 根据不同的字段/整数进行选择和分组
- git - 如何查看我推送的所有远程分支
- mysql - 表univ/#sql-bf4_4的外键约束错误:
- python-3.x - 如何使用 .aws 中的所有凭据执行 Boto3 脚本?
- nextcloud - 如何在 javascript 中获取 nextcloud 应用程序路径的路径
- firebase - 为什么颤振会为类内的 Firestore 方法返回错误,但在小部件内却很好?
- python - 如何将类构建到 Python 模块中
- python - AttributeError: 'list' object has no attribute 'SeqRecord' - 在尝试使用 Biopython>SeqIO 从 fasta 文件中切片多个序列时
- python - 字符串上的条(字符)