【问题标题】:Sticky Footer floating in page when resizing (reasked)调整大小时在页面中浮动的粘滞页脚(重新请求)
【发布时间】:2015-11-13 08:12:10
【问题描述】:

这个问题是几年前发布的By Sally,但她自己解决了,她的解决方案对我不起作用。

我已经浏览了该网站上几乎所有相关的粘性页脚页面以及其他地方的一些页面,但我找不到任何可以回答这个问题的东西。我确信这与我的布局有关,但我已经尝试了我研究过和能想到的所有方法,这是我最接近我满意的粘性页脚的方法。

这是我正在使用的 HTML。

<body>
    <div id="container">
        <header class="main-header">
            <a href="index.html"> <img src="logo3.png" alt="logo" /> </a>
            <ul class="main-nav">
                <li><a id="home" href="index.html">Home</a>
                </li>
            </ul>
            <ul class="second-nav">
                <li><a id="about" href="About.html">About Us</a>
                </li>
                <li><a id="portfolio" href="Portfolio.html">Portfolio</a>
                </li>
                <li><a href="SportsComplex.html">Sports Complex</a>
                </li>
                <li><a href="Contact.html">Contact Us</a>
                </li>
            </ul>
        </header>

        <body class="body">
            <div class="frameT">
                <div class="frameTC">
                    <div class="thumb" id="thumbs">
                        <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">_______</span>
                        </a>
                        <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">________</span>
                        </a>
                        <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">________</span>
                        </a>
                        <span class="stretch"></span>
                    </div>
                </div>
            </div>
        </body>

        <footer class="footer">
            <div class="quote">
                <h6>""</h6>
                <p> - </p>
            </div>
        </footer>
    </div>
</body>

和 CSS

/*header*/
.main-header {
    display: inline-block;
    position: relative;
    margin: 1%;
    width: 98%;
    top: 0;
    left: 0;
    min-width: 904px;
    z-index: 10;
    border: 0px solid #2675a9;
    border-top: none;
    border-radius: 0 0 0 0;
    background-color: #606060;
    background-color: rgb(29, 67, 129);
    -webkit-box-shadow:0 1px 5px black;
    -moz-box-shadow:0 1px 5px black;
    box-shadow:0 1px 5px black;
}

.main-header:after {
    content: " ";
    display: table;
    clear: both;
}

.main-header li {
    display: inline;
}

.main-header img {
    position: relative;
    float: left;
    top: 5.5px;
    left: 5.5px;
    width: 60px;
    height: 60px;
}

.main-nav {
    float: left;
    margin: 12.5px 0 12.5px 5px;
    padding: 0;
}

.main-nav a {
    text-shadow: 0.06em 0.08em #2666b1;
    letter-spacing: 4px;
    color: #ebebeb;
    font-family: StonyIsland;
    display: block;
    font-size: 2.5em;
    padding: 0px 10px;
    text-decoration: none;
    margin: 0px;
    font-weight: 300;
}

.logo {
    height: 50px;
    width: 50px;
    top: 0;
    left: 0;
    padding: 10.5px;
    margin: 0;
}

.second-nav {
    float: right;
    border-radius: 4px;
    margin-bottom: 5px;
    margin-top: 5px;
    margin-left: 0;
    margin-right: 0;
    border: none;
    padding: 9.5px;
}

.second-nav > li {
    float: left;
    border: solid 1px #ebebeb;
    border-bottom: none;
    border-top: none;
    border-right: none;
}

.second-nav li:first-child {
    border-left: none;
}

.second-nav li:second-child {
    border-left: none;
}

.second-nav a {
    color: #ebebeb;
    display: block;
    font-family: Capsuula;
    font-size: 1.13em;
    padding: 10px 30px;
    text-decoration: none;
}

a:hover{
    text-shadow: none;
    color: rgb(237, 12, 12);
}

/*body*/
html {
    position: relative;
    height: 100%;
    overflow-x: hidden;
}

ul {
    list-style-type: none;
}

a {
    text-decoration: none;
    font-size: 1.5em;
}

#wrap {
    min-height: 100%;   
}

#main {
    padding-bottom: 60px;
}

body {
    height: 100%;
    margin: 0 0 60px;
    background-color: rgb(255, 255, 255);
}

/*body location*/

 #thumbs {   
    width: auto;
    margin: 0;
    text-align: center;
    -ms-text-justify: distribute-all-lines;
    text-justify: distribute-all-lines;
}

#thumbs a {
    vertical-align: top;
    display: inline-block;
    *display: inline;
    zoom: 1;
    margin-left: 2%;
    margin-right: 2%;
    margin-bottom: 4em;
    margin-top: 12%;
}

#thumbs img {
    width: 300px;
    height: 300px;
    background-color: grey;
    border-radius: 60px;
    box-shadow: 0 1px 20px black;
}

.caption {
    display: block;
}

/*footer*/

footer {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 60px;
    width: 100%;
    background-color: rgba(255, 255, 255) transparent;
    background-color: rgba(255, 255, 255, 0.5);
}

.footer .quote {
    float: right;
    color: rgb(56, 56, 56);
}

.footer h6 {
    font-size: 15px;
    font-family: Capsuula;
    margin: 0;
    padding: 7px;
}

.footer p {
    font-size: 21px;
    font-family: Capsuula;
    float: right;
    margin: 0;
    padding;
    5px;
    padding-right: 12px;
}

这是我的JSfiddle

在我正常的全屏中,三个 300 像素 x 300 像素的正方形排成一行,一切都很好,但是当窗口尺寸减小时(就像我小提琴中的那个),正方形变成两条线并被推离屏幕。在您滚动之前,页脚会一直停留在屏幕底部,然后它会一直停留在原地,不会跟随页面底部。

当方块被强制分成两行时,我希望页脚被推到屏幕底部。

-或-

停留在屏幕底部并与用户一起滚动。

任何帮助将不胜感激!

【问题讨论】:

  • 你有两个bodys——一个在另一个里面。不确定这是否与您的问题有关,但它是无效的。
  • 你试过在.footer上设置position: fixed吗?或者在#container 上设置position: relative?有点不清楚您要的是什么,但我认为这些可能会满足您的要求。
  • 我之前尝试过修复,但它没有按预期工作。然而,在解决了身体问题后,它现在正在工作。感谢您的帮助!

标签: html css footer sticky-footer


【解决方案1】:

我去掉了多余的body,把它变成了一个div。我在页脚之前结束了容器并添加了一个push div,高度与footer 相等。似乎现在可以工作了。查看fiddle

/*header*/
 .main-header {
    display: inline-block;
    position: relative;
    margin: 1%;
    width: 98%;
    top: 0;
    left: 0;
    min-width: 904px;
    z-index: 10;
    border: 0px solid #2675a9;
    border-top: none;
    border-radius: 0 0 0 0;
    background-color: #606060;
    background-color: rgb(29, 67, 129);
    -webkit-box-shadow:0 1px 5px black;
    -moz-box-shadow:0 1px 5px black;
    box-shadow:0 1px 5px black;
}
.main-header:after {
    content:" ";
    display: table;
    clear: both;
}
.main-header li {
    display: inline;
}
.main-header img {
    position: relative;
    float: left;
    top: 5.5px;
    left: 5.5px;
    width: 60px;
    height: 60px;
}
.main-nav {
    float: left;
    margin: 12.5px 0 12.5px 5px;
    padding: 0;
}
.main-nav a {
    text-shadow: 0.06em 0.08em #2666b1;
    letter-spacing: 4px;
    color: #ebebeb;
    font-family: StonyIsland;
    display: block;
    font-size: 2.5em;
    padding: 0px 10px;
    text-decoration: none;
    margin: 0px;
    font-weight: 300;
}
.logo {
    height: 50px;
    width: 50px;
    top: 0;
    left: 0;
    padding: 10.5px;
    margin: 0;
}
.second-nav {
    float: right;
    border-radius: 4px;
    margin-bottom: 5px;
    margin-top: 5px;
    margin-left: 0;
    margin-right: 0;
    border: none;
    padding: 9.5px;
}
.second-nav > li {
    float: left;
    border: solid 1px #ebebeb;
    border-bottom: none;
    border-top: none;
    border-right: none;
}
.second-nav li:first-child {
    border-left: none;
}
.second-nav li:second-child {
    border-left: none;
}
.second-nav a {
    color: #ebebeb;
    display: block;
    font-family: Capsuula;
    font-size: 1.13em;
    padding: 10px 30px;
    text-decoration: none;
}
a:hover {
    text-shadow: none;
    color: rgb(237, 12, 12);
}
/*body*/
 html {
    position: relative;
    height: 100%;
    overflow-x: hidden;
}
ul {
    list-style-type: none;
}
a {
    text-decoration: none;
    font-size: 1.5em;
}
#wrap {
    min-height: 100%;
}
#main {
    padding-bottom: 60px;
}
body {
    height: 100%;
    margin: 0 0 60px;
    background-color: rgb(255, 255, 255);
}
/*body location*/
 #thumbs {
    width: auto;
    margin: 0;
    text-align: center;
    -ms-text-justify: distribute-all-lines;
    text-justify: distribute-all-lines;
}
#thumbs a {
    vertical-align: top;
    display: inline-block;
    *display: inline;
    zoom: 1;
    margin-left: 2%;
    margin-right: 2%;
    margin-bottom: 4em;
    margin-top: 12%;
}
#thumbs img {
    width: 300px;
    height: 300px;
    background-color: grey;
    border-radius: 60px;
    box-shadow: 0 1px 20px black;
}
.caption {
    display: block;
}
/*footer*/
.push{height:60px;}
 footer {
    position: relative;
    left: 0;
    bottom: 0;
    height: 60px;
    width: 100%;
    background-color: rgba(255, 255, 255) transparent;
    background-color: rgba(255, 255, 255, 0.5);
}
footer .quote {
    float: right;
    color: rgb(56, 56, 56);
}
footer h6 {
    font-size: 15px;
    font-family: Capsuula;
    margin: 0;
    padding: 7px;
}
footer p {
    font-size: 21px;
    font-family: Capsuula;
    float: right;
    margin: 0;
    padding;
    5px;
    padding-right: 12px;
}
<body>
    <div id="container">
        <header class="main-header"> <a href="index.html"> <img src="logo3.png" alt="logo" /> </a>

            <ul class="main-nav">
                <li><a id="home" href="index.html">Home</a>

                </li>
            </ul>
            <ul class="second-nav">
                <li><a id="about" href="About.html">About Us</a>

                </li>
                <li><a id="portfolio" href="Portfolio.html">Portfolio</a>

                </li>
                <li><a href="SportsComplex.html">Sports Complex</a>

                </li>
                <li><a href="Contact.html">Contact Us</a>

                </li>
            </ul>
        </header>
        <div class="body">
            <div class="frameT">
                <div class="frameTC">
                    <div class="thumb" id="thumbs"> <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">_______</span>
                        </a>
 <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">________</span>
                        </a>
 <a id="single_image1" href=".html"><img src="http://placehold.it/300x300" alt="" />
                            <span class="caption">________</span>
                        </a>
 <span class="stretch"></span>

                    </div>
                </div>
            </div>
        </div>
            </div>
    <div class="push"></div>
        <footer class="footer">
            <div class="quote">
                 <h6>"Hello"</h6>

                <p>-</p>
            </div>
        </footer>
</body>

【讨论】:

  • 这样它会一直停留在屏幕底部
  • 如果您希望页脚始终可见,则只需使用位置固定并删除推送 div jsfiddle.net/sfr0d0zL/3
  • 我想最后是两个身体元素让我失望了。固定位置没有像我之前想要的那样工作,但在它完美工作之后!我无法让推送技术发挥作用,但这很好,我更喜欢固定的。感谢您的帮助!
  • 对于固定工作,您需要在内容 div 中添加一个 margin-bottom。等于推的高度。然后它将起作用。我忘记了。投票并获得徽章;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-01
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
  • 2011-02-10
  • 1970-01-01
  • 2012-09-21
相关资源
最近更新 更多