html - 我怎样才能让我的代码响应调整页面大小
问题描述
我正在尝试为简单的主页制作代码。
有 sub1, sub2 为一个
html, body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, textarea, blockquote {
margin: 0;
padding: 0;
border: 0;
width : 100%;
height: 100%;
}
.main_wrap {
position: relative;
width: 100%;
height: 100%;
}
.sub1 {
display: inline-block;
float: left;
width: 49%;
height: 100%;
background-color: #0a4e85;
text-align: center;
display: table;
border: 5px solid white;
}
.sub2 {
display: inline-block;
float: left;
width: 50%;
height: 100%;
background-color: white;
text-align: center;
display: table;
border: 5px solid #0a4e85;
}
.main_title1, .main_title2{
color : white;
text-align: center;
line-height: 1.55;
white-space: nowrap;
font-size: 70px;
display: table-cell;
vertical-align: middle;
font-weight: 500;
text-decoration: none;
}
<html>
<head>
<title>Main</title>
</head>
<body>
<div class="main_wrap">
<div class="sub1"><div class="main_title1"><a href="javascript:goPageList();" >A</a></div></div>
<div class="sub2"><div class="main_title2"><a href="javascript:goPageMonth();" style="color: #0a4e85" >B</div></div>
</div>
</body>
</html>
菜单。每个 div 垂直分割窗口。
但是当我减小窗口宽度大小时,sub2 的第二个 div 低于 sub1。
我想让 sub1,sub2 保持一致。我能做些什么来修复它?
谢谢!!
解决方案
添加box-sizing: border-box;
body标签
html, body, div, h1, h2, h3, h4, h5, h6, p, ul, ol, li, dl, dt, dd, img, form, fieldset, input, textarea, blockquote {
margin: 0;
padding: 0;
border: 0;
width : 100%;
height: 100%;
box-sizing: border-box;
}
.main_wrap {
position: relative;
width: 100%;
height: 100%;
}
.sub1 {
display: inline-block;
float: left;
width: 50%;
height: 100%;
background-color: #0a4e85;
text-align: center;
display: table;
border: 5px solid white;
}
.sub2 {
display: inline-block;
float: left;
width: 50%;
height: 100%;
background-color: white;
text-align: center;
display: table;
border: 5px solid #0a4e85;
}
.main_title1, .main_title2{
color : white;
text-align: center;
line-height: 1.55;
white-space: nowrap;
font-size: 70px;
display: table-cell;
vertical-align: middle;
font-weight: 500;
text-decoration: none;
}
<html>
<head>
<title>Main</title>
</head>
<body>
<div class="main_wrap">
<div class="sub1"><div class="main_title1"><a href="javascript:goPageList();" >A</a></div></div>
<div class="sub2"><div class="main_title2"><a href="javascript:goPageMonth();" style="color: #0a4e85" >B</div></div>
</div>
</body>
</html>
推荐阅读
- mysql - MySql:在不使用联合的情况下获取两个表记录
- sql - Sybase 在分隔符上拆分数据
- swift - 我希望我的 tableview 在看到 firestore 数据库发生变化后重新加载
- c# - 将 JSON 解析为 DataTable 时出现 JsonSerializationException
- python - 在 Python 中将 Google 地图连接到 SHP 文件
- dialogflow-es - Account linking in Google Dialogflow
- r - 如何在R中将宽数据转换为长类型?
- java - 在测试类(Junit)中调用静态方法
- php - how to manage returned customer in oauth 2.0 php?
- asp.net - Razor 页面中的多个提交按钮无法找到处理程序 pageName?handler=OnPostUploadImage