我有一个网页布局。由三部分组成。布局非常简单,工作正常。小屏幕的问题是标题扩展并覆盖了它下面的容器。我的问题是,如何让 header container 展开并且同时不覆盖它下面的容器?请排除固定高度。例如(高度:150 像素;)。高度必须设置为自动或任何使其响应的模式。
这是 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="repeat.css">
</head>
<body>
<div class="header-container">
<div>
<ul class="left">
<li>home</li>
<li>menu</li>
<li>links</li>
<li>contacts</li>
</ul>
<ul class="right">
<li>home</li>
<li>menu</li>
<li>links</li>
<li>contacts</li>
</ul>
</div>
</div>
<div class="main-container">
<div class="left-column">
<div class="wrap">
</div>
</div>
<div class="main-column">
<div>
<p> this part should not be covered when the header
container change its height </p>
<p> this part should not be covered when the header
container change its height </p>
<p> this part should not be covered when the header
container change its height </p>
<p> this part should not be covered when the header
container change its height </p>
<p> this part should not be covered when the header
container change its height </p>
<p> this part should not be covered when the header
container change its height </p>
</div>
</div>
</div>
</body>
</html>
CSS 代码:
* {
margin: 0px;
padding: 0px;
}
.header-container{
position:fixed;
top:0;
left:0;
width:100%;
height:80px;
background: #ccc;
box-sizing: border-box;
z-index: 10;
}
.left{
padding-left: 50px;
float:left;
}
.right{
padding-left: 300px;
float: left;
}
.main-container{
position:absolute;
margin-top: 80px;
left:0px;
width:100%;
height: calc(100% - 80px);
box-sizing: border-box;
background-color: pink;
z-index:1;
}
.left-column{
position:relative;
padding:0;
margin:0;
float:left;
width:20%;
height:100%;
background-color: #4db6ac;
}
.main-column{
position:relative;
padding:0;
margin:0;
float:left;
width:80%;
height:100%;
background-color: #00e5ff;
}
@media screen and (max-width:720px){
.header-container{
height: auto;
}
.left-column{
display:none;
}
.main-column{
width:100%;
}
}
最佳答案
我使用 jQuery 得到了解决方案。该解决方案由 Marc Audet 发布。您可以通过此链接找到解决方案: CSS, image with height:auto, covers div beneath it upon screen resize (phone held horizontally)
如果有人有另一种仅使用 css 的解决方案,我们将不胜感激。
关于html - 如何防止标题高度覆盖其下方的容器并同时使其自动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49375230/