html - CSS 底部栏未正确显示 chrome

标签 html css

我的网页底部有一个栏,代码如下:

<div class="casa5">
<label style="margin:auto;"><font color="orange">&#9733;</font> my text <font color="orange">&#9733;</font></label>
</div>

在这里你可以看到CSS:

.casa5 {
 background-color:#0C0C0C;
 width:100%;
 height:24px;
 position:absolute;
 left: 0;
 right: 0;
 text-align:center;
 font: 90% 'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
 color:#E8E8E8;
}

div 显示在页面底部,如您所见:

我正在使用火狐浏览器。顺便说一句,我遇到了麻烦,因为当我用 Chrome 打开页面时,我有这个 View :

如您所见,当您使用 Firefox 打开页面时,该栏位于页面底部,但是当我使用 Chrome 加载同一页面时,我的 div 和底部之间有一个空隙。

我希望只有当我向下滚动到最后时,该栏才显示在页面底部。我该如何解决这个问题?

最佳答案

  • 你只需要添加 bottom: 0 到你的 css:

    .casa5 {
        background-color:#0C0C0C;
        width:100%;
        height:24px;
        position:absolute;
        left: 0;
        right: 0;
        text-align:center;
        font: 90%'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
        color:#E8E8E8;
        bottom: 0;
    }
    

    此外,您可能应该将 position:absolute; 更改为 position: fixed;,以便无论用户是否滚动,它始终位于底部。

    Fiddle

  • 但是,如果您希望它始终位于页面末尾,您可以这样做:

    html {
        position: relative;
    }
    .casa5 {
        background-color:#0C0C0C;
        width:100%;
        height:24px;
        position: absolute;
        left: 0;
        right: 0;
        text-align:center;
        font: 90%'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
        color:#E8E8E8;
        bottom: 0;
    }
    

    它将 html 更改为 position: relative 并将页脚保持在 position: absolute

    Fiddle

    根据 http://mystrd.at/modern-clean-css-sticky-footer/ 的建议

关于html - CSS 底部栏未正确显示 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21867368/

相关文章:

html - 表格填充不起作用

java - 如何将原始 HTML 从 java spring Controller 传递到 jsp View

html - 仅当鼠标悬停在 li 类 css 上时显示 ul 类

Javascript 目标仅被点击的元素

html - 在导航栏品牌附近添加灯光效果到背景

JavaScript HTML 从 JavaScript 代码更改 HTML 元素

css - div 忽略样式表中的高度

html - Outlook 未在签名中呈现我的 CSS

css - 我可以仅使用 CSS 添加类吗?

css - 我想知道如何编程 fix-height-div 和 flexible-height-div