如何使用CSS动态调整内容区域大小,没有javascript [英] How to resize content area with CSS dynamically and no javascript
本文介绍了如何使用CSS动态调整内容区域大小,没有javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要的是:
- 当浏览器窗口调整大小时,蓝色区域的大小会改变。
- 标题是可见的。
- 蓝色区域开始于标题结束处(不在标题之上或之上)。
- the blue area resizes with when the browser window resizes.
- The header is visible.
- the blue area starts where the header finishes (not behind the header or above).
- the blue area ends before the footer.
- between the blue area and the footer exist 5 yellow pixels.
这是否只能使用CSS和HTML(没有任何javascript)?
Is this possible only with CSS and HTML ( without any javascript ) ?
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8"/>
<title>Test</title>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
<style>
*{
margin:0px;
padding:0px;
}
header, nav, article, footer, address {
display: block;
}
header{
position:relative; height: 50px; background-color:#2b2b2b;
}
footer{
height: 50px;
width:100%;
bottom: 0px;
position: fixed;
background: red;
}
#explorer{
position:relative; bottom:55px;
}
#sections{
width: 100%; height: 100%; bottom: 55px; position:fixed; background: blue;
}
</style>
</head>
<body style="background-color:yellow">
<header >
<h1>Test</h1>
</header>
<div id="explorer" >
<div id="sections" >
</div>
</div>
<footer>
/* Footer Content */
</footer>
</body>
</html>
推荐答案
我认为Kit的代码只需要一个调整也就是说,我们必须从节 div&它会工作很好。同时测试下面的代码,我注意到,如果我们减少的高度超过限制,页脚实际上是在标题的上方。虽然,实际上,高度永远不会这么少,但仍然你可能想添加z-index:5000到标头
I think Kit's code needs just one adjustment & that is we have to remove the height:100% from the sections div & it will work just fine. Also while testing the following code, i noticed that if we reduce the height beyond a limit the footer actually comes above the header. Although, practically the height would never be so less, but still you might want to add z-index:5000 to header tag
这篇关于如何使用CSS动态调整内容区域大小,没有javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文