如何将页脚设置为页面底部?

问题描述:

代码:如何将页脚设置为页面底部?

<!DOCTYPE html> 
<html> 
<head> 
<title>Slide-Up Dialogue Box</title> 
<style type="text/css"> 
body { 
margin: 0; 
padding: 0; 
height: 100%; 
} 
#container { 
min-height: 100%; 
position: relative; 
} 
#header { 
background: #ff0; 
padding: 10px; 
} 
#body { 
padding: 10px; 
padding-bottom: 60px; 
} 
#footer { 
position: absolute; 
bottom: 0; 
width: 100%; 
height: 30px; 
background: #6cf; 
} 
</style> 
</head> 
<body> 
<div id="container"> 
<div id="header"></div> 
<div id="body"></div> 
<div id="footer"> 
Who is Online? 
</div> 
</div> 
</body> 
</html> 

我怎样才能把页脚在页面的底部?我尝试过填充,底部和边距的尝试,但迄今为止我还没有取得很大的成功。有人能告诉我如何将页脚放在页面底部吗?谢谢

+0

尝试添加位置:固定为页脚。 – sinisake

你可以这样做一个先生:

body { 
margin: 0; 
padding: 0; 
height: 100%; 
} 
#container { 
min-height: 100%; 
position: relative; 
} 
#header { 
background: #ff0; 
padding: 10px; 
} 
#body { 
padding: 10px; 
padding-bottom: 60px; 
} 
#footer { 
position: fixed;; 
bottom: 0; 
width: 100%; 
height: 30px; 
background: #6cf; 
text-align:center; 
} 

HERE MY CODE

您需要将body高度设置为100%。目前,该机构仅涵盖您所拥有的内容。没有为身体元素设置明确的高度。

由于身体需要计算父元素的100%,因此也应将html高度设置为100%。

html, 
 
body { 
 
    height: 100%; 
 
}
<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Slide-Up Dialogue Box</title> 
 
    <style type="text/css"> 
 
    body { 
 
     margin: 0; 
 
     padding: 0; 
 
     height: 100%; 
 
    } 
 
    #container { 
 
     min-height: 100%; 
 
     position: relative; 
 
    } 
 
    #header { 
 
     background: #ff0; 
 
     padding: 10px; 
 
    } 
 
    #body { 
 
     padding: 10px; 
 
     padding-bottom: 60px; 
 
    } 
 
    #footer { 
 
     position: absolute; 
 
     bottom: 0; 
 
     width: 100%; 
 
     height: 30px; 
 
     background: #6cf; 
 
    } 
 
    </style> 
 
</head> 
 

 
<body> 
 
    <div id="container"> 
 
    <div id="header"></div> 
 
    <div id="body"></div> 
 
    <div id="footer"> 
 
     Who is Online? 
 
    </div> 
 
    </div> 
 
</body> 
 

 
</html>

如果你的目标是 “修理” 你的元素在屏幕的底部,设置:

position: fixed; 
 
bottom: 0;

在一个侧面说明,这可能是一个好主意,你开始学习HTML5元素,如“尾”,而不是使用div的一切。另请注意,身份证是独一无二的,造型最适用于大众/一般(使用班级)。