【发布时间】:2015-08-06 04:56:38
【问题描述】:
我想为一个网页设计一个结构,但是我有一个问题,我不能单独使用它。这就是我想要的:
一个包含 3 个部分的网页:
1-header
2-content( has 2 parts, a sidebar and a content section)
3-footer
我想要这些特征:
1- if in the content section there is nothing then footer stays at the bottom, if we have content, footer pushes down and stays after my content
2- my sidebar(exist in the content section) take 100% height of content section and connects to footer
像这样:
我用这段代码构建了它,它可以工作,但我的问题是,如果侧边栏区域的内容变大,侧边栏和主要内容区域会重叠页脚!我希望在这种情况下,页脚留在我的内容之后。
我在工作中使用 Twitter Bootstrap。我不想使用仅在新浏览器中可用的方法。至少 IE 9。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap.min.css" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container-fluid">
<div class="row header">
<div>header</div>
</div>
<div class="row content">
<div class="col-lg-2 sidebar">
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
<div>content</div>
</div>
<div class="col-lg-10">content</div>
</div>
<div class="row footer">
<div>footer</div>
<div>footer</div>
<div>footer</div>
<div>footer</div>
<div>footer</div>
</div>
</div>
这是 CSS:
body,html{
height: 100%;
}
.container-fluid {
height:100%;
}
.header{
background-color: #ccff55;
}
.content{
background-color: #445566;
height: -webkit-calc(100% - 10%);
}
.sidebar{
background-color: #446655;
height: 100%;
}
.footer{
background-color: #11ff99;
}
【问题讨论】:
-
这是对 'calc' 属性的惊人使用... 100% - 10%。哈哈……你试过90%吗?哈哈...
-
@connexo:不,这不是我想要的,这不是重复的帖子。你提到的那篇文章是我问题的一半,只是将页脚放在底部。我也想要 100% 的内容
-
@SeanStopnik:这是我朋友的结构,而不是 -webkit-calc(100% - 10%);我们可以写 -webkit-calc(100% - 50px);例如。
-
@Robert: 如果我们的内容越来越小于屏幕高度,页脚应该像粘性页脚一样留在底部,但是如果我们有很多内容,我们的页脚应该向下并留在后面内容。始终页脚应该在内容之后
标签: html css twitter-bootstrap