Html 将div定位在容器元素的底部

Html 将div定位在容器元素的底部,html,css,positioning,css-position,Html,Css,Positioning,Css Position,我正在设计的网页布局像这样: 编辑:注意:我不是想得到一个粘性页脚。我只想把它放在页面底部。回答前请先看小提琴 我试图定位在页面底部的页脚,但无法,因为你可以看到在上面的链接。我尝试了在互联网上找到的一切,包括设置容器元素的位置:相对;和页脚的位置:绝对和底部:0但事实上,如果您将container div添加到代码中并使其位置为:relative,那么似乎什么都不起作用,并将以下css添加到页脚:位置:绝对;底部:0,页脚似乎消失在某处。很长一段时间以来,这个问题一直困扰着我,到目前为止,我找

我正在设计的网页布局像这样:

编辑:注意:我不是想得到一个粘性页脚。我只想把它放在页面底部。回答前请先看小提琴

我试图定位在页面底部的页脚,但无法,因为你可以看到在上面的链接。我尝试了在互联网上找到的一切,包括设置容器元素的位置:相对;和页脚的
位置:绝对
底部:0
但事实上,如果您将container div添加到代码中并使其
位置为:relative,那么似乎什么都不起作用
,并将以下css添加到页脚:
位置:绝对;底部:0,页脚似乎消失在某处。很长一段时间以来,这个问题一直困扰着我,到目前为止,我找到的唯一解决方案是设置页眉、内容和页脚的
位置:static,它破坏了服务器的用途,破坏了整个布局,看起来非常丑陋。我想避免使用javascript。请帮忙,提前谢谢

编辑:我需要的说明:

其中蓝色是页脚,深蓝色是页眉,浅蓝色是实际内容,粉色是粘性div。我不想让页脚变得粘性,但我想让它像普通页面上的一样,唯一的问题是它不会停留在页面底部(请参阅)

使用此选项

在css中添加此css属性

html, body{height:100%}


div#footer {
        color: white;
        background: rgba(68, 68, 68, 0.8);
        width: 100%;
        position:absolute;
        bottom:0;
    }
用这个

在css中添加此css属性

html, body{height:100%}


div#footer {
        color: white;
        background: rgba(68, 68, 68, 0.8);
        width: 100%;
        position:absolute;
        bottom:0;
    }

您可以为此使用粘滞页脚方法。读这个

例如,这样写:

HTML

<div class="container"></div>

<div class="footer"></div>

检查此项了解更多信息

您可以使用粘滞页脚方法进行此操作。读这个

例如,这样写:

HTML

<div class="container"></div>

<div class="footer"></div>

检查此项了解更多信息是否有用我不知道您是否解决了此问题,但我遇到了类似的问题,解决方法如下:

<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" " http://w3.org/TR/html4/loose.dtd">
<html>
<style type="text/css" >
div#mypage {
    top:0;
    background: purple;
    color: white;
}
div#pageheader {
    top:0;
    left:0;
    height: 20%;
    position:absolute;
    width:100%;
    background: green;
    color: white;
 }
div#pagecontent {
}
div#contentleft {
    display: inline-block;
    background: blue;
    position:absolute;
    border-radius: 2px;
    left:0%;
    right: 15%;
    width:15%;
    height: 92.5%;
    top: 5%;
    color: white;
}
div#contentcenter {
    display: inline-block;
    background: yellow;
    position:absolute;
    border-radius: 2px;
    left:15%;
    right: 30%;
    width:80%;
    height: 92.5%;
    top: 5%;
    color: black;
}
div#contentright {
    display: inline-block;
    background: red;
    position:absolute;
    border-radius: 2px;
    left:95%;
    right: 5%;
    width:5%;
    height: 92.5%;
    top: 5%;
    color: white;
}
div#pagefooter {
    color: white;
    background: rgba(68, 68, 68, 0.8);
    width: 100%;
    height: 2.5%;
    position:fixed;
    left:0;
    bottom:0;
}
</style>
<head>
<title>Multiple Div's</title>
</head>
<body bgcolor="#cccccc">
<div id="mypage">
    <div id="pageheader">HDR</div>
    <div id="pagecontent">PAGE CONTENT
        <div id="contentleft">LEFT</div>
        <div id="contentcenter">CENTER</div>
        <div id="contentright">RIGHT</div>
    </div>
    <div id="pagefooter">FOOTER</div>
</div>
</div>
</body>
</html>

分区#mypage{
排名:0;
背景:紫色;
颜色:白色;
}
div#页眉{
排名:0;
左:0;
身高:20%;
位置:绝对位置;
宽度:100%;
背景:绿色;
颜色:白色;
}
第页内容{
}
div#content left{
显示:内联块;
背景:蓝色;
位置:绝对位置;
边界半径:2px;
左:0%;
右:15%;
宽度:15%;
身高:92.5%;
最高:5%;
颜色:白色;
}
内容中心分部{
显示:内联块;
背景:黄色;
位置:绝对位置;
边界半径:2px;
左:15%;
右:30%;
宽度:80%;
身高:92.5%;
最高:5%;
颜色:黑色;
}
div#contentright{
显示:内联块;
背景:红色;
位置:绝对位置;
边界半径:2px;
左:95%;
右:5%;
宽度:5%;
身高:92.5%;
最高:5%;
颜色:白色;
}
第页页脚{
颜色:白色;
背景:rgba(68,68,68,0.8);
宽度:100%;
身高:2.5%;
位置:固定;
左:0;
底部:0;
}
多分区
HDR
页面内容
左边
居中
正确的
页脚

我不知道您是否解决了此问题,但我遇到了类似的问题,解决方法如下:

<!DOCTYPE HTML PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" " http://w3.org/TR/html4/loose.dtd">
<html>
<style type="text/css" >
div#mypage {
    top:0;
    background: purple;
    color: white;
}
div#pageheader {
    top:0;
    left:0;
    height: 20%;
    position:absolute;
    width:100%;
    background: green;
    color: white;
 }
div#pagecontent {
}
div#contentleft {
    display: inline-block;
    background: blue;
    position:absolute;
    border-radius: 2px;
    left:0%;
    right: 15%;
    width:15%;
    height: 92.5%;
    top: 5%;
    color: white;
}
div#contentcenter {
    display: inline-block;
    background: yellow;
    position:absolute;
    border-radius: 2px;
    left:15%;
    right: 30%;
    width:80%;
    height: 92.5%;
    top: 5%;
    color: black;
}
div#contentright {
    display: inline-block;
    background: red;
    position:absolute;
    border-radius: 2px;
    left:95%;
    right: 5%;
    width:5%;
    height: 92.5%;
    top: 5%;
    color: white;
}
div#pagefooter {
    color: white;
    background: rgba(68, 68, 68, 0.8);
    width: 100%;
    height: 2.5%;
    position:fixed;
    left:0;
    bottom:0;
}
</style>
<head>
<title>Multiple Div's</title>
</head>
<body bgcolor="#cccccc">
<div id="mypage">
    <div id="pageheader">HDR</div>
    <div id="pagecontent">PAGE CONTENT
        <div id="contentleft">LEFT</div>
        <div id="contentcenter">CENTER</div>
        <div id="contentright">RIGHT</div>
    </div>
    <div id="pagefooter">FOOTER</div>
</div>
</div>
</body>
</html>

分区#mypage{
排名:0;
背景:紫色;
颜色:白色;
}
div#页眉{
排名:0;
左:0;
身高:20%;
位置:绝对位置;
宽度:100%;
背景:绿色;
颜色:白色;
}
第页内容{
}
div#content left{
显示:内联块;
背景:蓝色;
位置:绝对位置;
边界半径:2px;
左:0%;
右:15%;
宽度:15%;
身高:92.5%;
最高:5%;
颜色:白色;
}
内容中心分部{
显示:内联块;
背景:黄色;
位置:绝对位置;
边界半径:2px;
左:15%;
右:30%;
宽度:80%;
身高:92.5%;
最高:5%;
颜色:黑色;
}
div#contentright{
显示:内联块;
背景:红色;
位置:绝对位置;
边界半径:2px;
左:95%;
右:5%;
宽度:5%;
身高:92.5%;
最高:5%;
颜色:白色;
}
第页页脚{
颜色:白色;
背景:rgba(68,68,68,0.8);
宽度:100%;
身高:2.5%;
位置:固定;
左:0;
底部:0;
}
多分区
HDR
页面内容
左边
居中
正确的
页脚

正如我所说,我再次重申,我不是在寻找固定或粘性的页脚。我只想把它放在页面底部!“页面底部”模棱两可!每个人都在猜测你想做什么,所以请解释一下你想要更好的行为。对不起,如果我没有把你自己弄清楚的话。我现在添加了一个简单的例子,以帮助你们更好地理解我的问题。正如我所说的,我再次重申,我不是在寻找固定或粘性的页脚。我只想把它放在页面底部!“页面底部”模棱两可!每个人都在猜测你想做什么,所以请解释一下你想要更好的行为。对不起,如果我没有把你自己弄清楚的话。现在,我添加了一个简单的插图,帮助你们更好地理解我的问题。我不想寻找粘性页脚,而是想把它放在页面底部。如果我的答案不是你们想要的,那个么@rohit answer是对的。不想寻找粘性页脚,但我想把它放在页面底部,若我的答案不是你们想要的,那个么@rohit-answer是对的。我想这是我在这本书上见过的最令人困惑的问题。如果你只是想让你的页脚在页面的底部,只要不给它一个位置,它就会坐在内容下面。我不明白你的问题是什么。不,它不在内容下面,这就是问题所在。我想这是我见过的最令人困惑的问题。如果你只想把页脚放在页面底部,那就这样做吧