Footer overlaps content above it

可紊 提交于 2021-02-08 04:58:35

问题


I sticked footer to bottom of page, but somehow it doesn't keep flow of previous element, which is now likely below (in Z axis) footer. Footer should be just lower than .center-main element. However that one has absolute property, cause either way it doesn't fit in center of page - when other than 'position: absolute' it is below .cat-menu element, BUT footer still overlaps it.

Problematic CSS part:

.cat-menu
{
    width: 20%;
    margin: 3px;
    display: inline-block;
    border:1px solid blue;

}

.center-main
{
    width: 79%;
    position: absolute;
    margin: 3px;
    display: inline-block;
    border: 1px solid red;
}

footer
{
    clear: both;
    border: 2px solid red;
    text-align: center;
    position: fixed;
    display: block;
    bottom: 0;
    width: 99.7%;
}

Whole page: https://jsfiddle.net/tnmmoLnq/1/ (those buttons at center of page are bad positioned on jsfiddle - on my PC they are ok).


回答1:


Your fixed footer will always be overlapping the container (unless it (the container) has a height set). What you need to do is create an outer-container that the footer will overlap, and an inner-container with a marin-bottom the same height as your footer.

FIDDLE

.center-main-inner
{
    width: 79%;
    position: relative;
    margin: 3px;
    display: inline-block;
    border: 1px solid #0000FF;
    margin-bottom:20px;
}

And here is static -- non fixed version:

updated fiddle



来源:https://stackoverflow.com/questions/34552858/footer-overlaps-content-above-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!