html - 响应式设计 - 调整窗口大小时 Div 消失
问题描述
当宽度值小于 800px 时,试图让两个 div 元素(.left
和)垂直显示。但是,当我尝试这样做时.right
,div消失了。.left
我从代码中删除了一些内容以保持简短。
有谁知道为什么会发生这种情况以及如何解决它?
这是我的代码:
* {
box-sizing: border-box;
}
body {
color: white;
}
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: #282C34;
}
.right {
right: 0;
background-color: #616161;
}
.centered {
position: absolute;
width: 100;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.container {
position: relative;
border-style: solid;
border-color: #92a8d1;
background-color: #92a8d1;
}
@media screen and (max-width:800px) {
.left,
.right {
width: 100%;
/* The width is 100%, when the viewport is 800px or smaller */
}
}
<div class="split left">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>asd</h2>
</div>
</div>
</center>
</div>
</div>
<div class="split right">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>fgh</h2>
</div>
</div>
</center>
</div>
</div>
谢谢你的帮助!
解决方案
* {
box-sizing: border-box;
}
body {
color: white;
margin: 0;
}
.split {
height: 100%;
width: 50%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: #282C34;
}
.right {
right: 0;
background-color: #616161;
}
.centered {
position: absolute;
width: 100;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.container {
position: relative;
border-style: solid;
border-color: #92a8d1;
background-color: #92a8d1;
}
@media screen and (max-width:800px) {
.left,
.right {
width: 100%;
height: 50%;
/* The width is 100%, when the viewport is 800px or smaller */
}
.split {
position: relative;
}
body {
height: 100vh;
}
}
<div class="split left">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>asd</h2>
</div>
</div>
</center>
</div>
</div>
<div class="split right">
<div class="centered">
<center>
<div class="container">
<div class="middle">
<div class="text">
<a></a>
</div>
</div>
<div class="information">
<h2>fgh</h2>
</div>
</div>
</center>
</div>
</div>
推荐阅读
- python - 寻求修改代码以从 A 列具有 X 数值的 Excel 工作表中提取数据。(即 value= 0 的所有行)
- angular - 多阶段表单验证角度
- node.js - Typescript node.js 可以从界面打印密钥吗?
- java - 使用模数和整数除法来确认帐号
- oracle - 我怎样才能找到收入比他们的经理少的员工?- ORACLE - SCOTT 数据库
- javascript - 无论 Javascript 的输入值如何,第一行(动态生成)始终显示
- python - TypeError: 'float object is not subscriptable from Machine Learning with Python for Everyone by Mark Fenner
- java - InputMismatchException Java第一个扫描仪工作第二个不
- jquery - 在 Webpacker 5 中加载 jQuery 的问题
- ssl - Heroku ACM 失败(未返回 HTTP 质询)