我需要帮助才能尝试将此页脚设置在固定位置。我正在学习,并试图制作一个合理的液体布局。这是一项正在进行的工作,但我不能继续,直到我把页脚放在正确的位置。
我的问题是它一直延伸到右边的窗口。有时它会创建一个滚动条而不遵循保证金规则。我通过使用可靠的谷歌尝试了我能想到的一切以及我能找到的东西。我使用了最新的chrome和firefox版本来查看它是否是Chrome问题。
我曾经有一个包装容器,但是我已经删除它并将页脚代码从一个地方移到另一个地方,试图找到一个适合它的地方。
body {
text-align: center;
margin-top: 0;
background-color: #1A1A1A;
background-image: url('#');
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;}
#logo {
background-color: rgba(53, 53, 53, 0.9);
padding: 10px;
position: relative;
margin-right: auto;
margin-left: auto;
margin-bottom: 5px;
height: 90px;
-webkit-border-bottom-left-radius: 5px;
-webkit-border-bottom-right-radius: 5px;
-moz-border-bottom-left-radius: 5px;
-moz-border-bottom-right-radius: 5px;
-ms-border-bottom-left-radius: 5px;
-ms-border-bottom-right-radius: 5px;
-o-border-bottom-left-radius: 5px;
-o-border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;}
#nav {
background-color: rgba(53, 53, 53, 0.9);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
-msborder-radius: 5px;
-o-border-radius: 5px;
border-radius: 5px;
padding: 0px;
position: relative;
margin-right: 0;
margin-left: 0;}
ul {
list-style: none;
margin: 0;
display: inline-block;
position: relative;}
li {
display: inline-block;
position: relative;}
a {
display: inline-block;
text-decoration: none;
height: 100px;
width: 100px;
position: relative;
text-align: center;}
#link1:hover {
background-color: #727272;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;}
#link1:active {
background-color: #ba6a15;}
#link2:hover {
background-color: #727272;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;}
#link2:active {
background-color: #ba6a15;}
#link3:hover {
background-color: #727272;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;}
#link3:active {
background-color: #ba6a15;}
#link4:hover {
background-color: #727272;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
-o-transition: all 0.3s;
transition: all 0.3s;}
#link4:active {
background-color: #ba6a15;}
#footer {
background-color: rgba(53, 53, 53, 0.9);
position: fixed;
bottom: 0;
width: 100%;
height: 22px;
padding: 3px;
color: #FFF;}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<header>
<div id="logo"><img src="#" alt="logo"></div>
<nav>
<ul>
<li id="link1"><a href="#"><img src="#" alt=""; height="100"; width="100"></a></li>
<li id="link2"><a href="#"><img src="#" alt=""; height="100"; width="100"></a></li>
<li id="link3"><a href="#"><img src="#" alt=""; height="100"; width="100"></a></li>
<li id="link4"><a href="#"><img src="#" alt=""; height="100"; width="100"></a></li>
</ul>
</nav>
</header>
<footer>Hello there!</footer>
</body>
答案 0 :(得分:4)
您可以将margin:0px;
设为body
,将box-sizing: border-box;
设为footer
JSFiddle - DEMO
body {
text-align: center;
background-color: #1A1A1A;
background-image: url('#');
background-position: center;
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
margin:0px;
}
#footer {
background-color: rgba(53, 53, 53, 0.9);
position: fixed;
bottom: 0;
width: 100%;
height: 22px;
padding: 3px;
color: #FFF;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
答案 1 :(得分:1)
这里错了:
#footer {
width: 100%;
padding: 3px;
}
您的页脚宽度设置为填充的100%+ 6px。
尝试添加此内容以使填充(和边框)成为页脚内容的一部分:
#footer{
box-sizing: border-box;
}
答案 2 :(得分:0)
试试这个:
<div id="footer">Hello there!</div>