html - 页脚 html 也显示在下方

标签 html css

<分区>


关闭 3 年前

我无法正确放置页脚。

我想将页脚保留在底部(可行),但实际上它显示在下方,我不明白为什么... 如果我的 body 太长,我可以向下滚动,但如果情况并非如此,我就不会。 找不到会导致此问题的页边距或与页脚相关的内容。

.footer {
    background-color: rgba(0, 0, 0, 0.7);
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    text-align: center;
    padding: 5px 0 5px 0;
    clear: both;
}

* {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    font-family: Poppins;
    font-weight: 400;
    background: url(../images/background.jpg);
    background-position: center;
    background-size: cover;
    overflow-y: scroll;
}

nav {
    padding: 8px;
}

.logo {
    float: left;
    padding: 8px;
    margin-left: 16px;
}

    .logo a {
        color: #ffffff;
        text-transform: uppercase;
        font-weight: 700;
        font-size: 22px;
        letter-spacing: 0px;
        text-decoration: none;
    }

nav ul {
    float: right;
}

    nav ul li {
        display: inline-block;
        float: left;
    }

        nav ul li:not(:first-child) {
            margin-left: 48px;
        }

        nav ul li:last-child {
            margin-right: 24px;
        }

        nav ul li a {
            display: inline-block;
            outline: none;
            color: #000;
            text-transform: uppercase;
            text-decoration: none;
            font-size: 14px;
            letter-spacing: 1.2px;
            font-weight: 600;
        }

@media screen and (max-width: 864px) {
    .logo {
        padding: 0;
    }

    .nav-wrapper {
        position: fixed;
        top: 0px;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: -1;
        background: #fff;
        opacity: 0;
        transition: all 0.2s ease;
    }

        .nav-wrapper ul {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 100%;
        }

            .nav-wrapper ul li {
                display: block;
                float: none;
                width: 100%;
                text-align: right;
                margin-bottom: 10px;
            }

                .nav-wrapper ul li:nth-child(1) a {
                    transition-delay: 0.2s;
                }

                .nav-wrapper ul li:nth-child(2) a {
                    transition-delay: 0.3s;
                }

                .nav-wrapper ul li:nth-child(3) a {
                    transition-delay: 0.4s;
                }

                .nav-wrapper ul li:nth-child(4) a {
                    transition-delay: 0.5s;
                }

                .nav-wrapper ul li:not(:first-child) {
                    margin-left: 0;
                }

                .nav-wrapper ul li a {
                    padding: 10px 24px;
                    opacity: 0;
                    color: #000;
                    font-size: 14px;
                    font-weight: 600;
                    letter-spacing: 1.2px;
                    transform: translateX(-20px);
                    transition: all 0.2s ease;
                }

    .nav-btn {
        position: fixed;
        right: 10px;
        top: 10px;
        display: block;
        width: 48px;
        height: 48px;
        cursor: pointer;
        z-index: 9999;
        border-radius: 50%;
    }

        .nav-btn i {
            display: block;
            width: 20px;
            height: 2px;
            background: #ffffff;
            border-radius: 2px;
            margin-left: 14px;
        }

            .nav-btn i:nth-child(1) {
                margin-top: 16px;
            }

            .nav-btn i:nth-child(2) {
                margin-top: 4px;
                opacity: 1;
            }

            .nav-btn i:nth-child(3) {
                margin-top: 4px;
            }
}

#nav:checked + .nav-btn {
    transform: rotate(45deg);
}

    #nav:checked + .nav-btn i {
        background: #000;
        transition: transform 0.2s ease;
    }

        #nav:checked + .nav-btn i:nth-child(1) {
            transform: translateY(6px) rotate(180deg);
        }

        #nav:checked + .nav-btn i:nth-child(2) {
            opacity: 0;
        }

        #nav:checked + .nav-btn i:nth-child(3) {
            transform: translateY(-6px) rotate(90deg);
        }

#nav:checked ~ .nav-wrapper {
    z-index: 9990;
    opacity: 1;
}

    #nav:checked ~ .nav-wrapper ul li a {
        opacity: 1;
        transform: translateX(0);
    }

.hidden {
    display: none;
}

.txt {
    color: white;
    font-size: 16px;
}

.container {
    margin-top: 1%;
}

.border-container {
    background-color: rgba(0, 0, 0, 0.7);
    margin-top: 7%;
    margin-bottom: 1%;
    margin-left: 15%;
    margin-right: 15%;
    padding: 5px;
    border-radius: 5px;
    max-height: 690px;
}

.container-text {
    margin-top: 1%;
    margin-bottom: 1%;
    margin-left: 1%;
    margin-right: 1%;
    padding: 1%;
    border-radius: 3px;
}

.text {
    font-size: 14px;
    color: white;
}

.h1 {
    color: white;
}

.logo-herbalife {
    height: 50px;
    width: 50px;
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 5%;
}

.social-logo {
    list-style: none;
    padding-right: 30px;
    display: inline;
    margin-right: 11px;
}

.fab {
    color: white;
}

.far {
    color: white;
}

* {
    margin: 0;
}

.active, .btn:hover {
    border-bottom: 2px solid #65bb00;
}

.well {
    position: relative;
}

.title-footer {
    color: white;
    font-weight: 700;
    font-size: 22px;
}

.text-footer {
    margin: 0 0 12px 0;
    color: white;
    font-weight: 600;
    font-size: 11px;
}

.gallery {
    background-color: rgba(0, 0, 0, 0.7);
    margin-top: 7%;
    margin-bottom: 4%;
    margin-left: 15%;
    margin-right: 15%;
    padding: 10px;
    border-radius: 3px;
    text-align: center;
}

    .gallery img {
        transition: 0.7s;
        padding: 10px;
        width: 300px;
        height: 300px;
    }

        .gallery img:hover {
            filter: grayscale(50%);
            transform: scale(1.1);
        }


.topnav a:hover {
    border-bottom: 5px solid #65bb00;
    padding-bottom: 8px;
    transition: all 0.3s linear;
    -webkit-transition: all 0.3s linear;
    -moz-transition: all 0.3s linear;
}

.topnav a.active {
    border-bottom: 5px solid #65bb00;
    padding-bottom: 8px;
}
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Accueil - Fab h24</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
    <script src="https://kit.fontawesome.com/6d0f7aa58c.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body class="body">
    <div class="container">
        <nav>
            <input type="checkbox" id="nav" class="hidden">
            <label for="nav" class="nav-btn">
                <i></i>
                <i></i>
                <i></i>
            </label>
            <div class="logo">
                <a href="index.html"><span style="color: #65bb00;">F</span>AB H24</a>
            </div>

            <div id="myDIV" class="nav-wrapper topnav">
                <ul>
                    <li><a href="index.html" class="txt active">Home</a></li>
                    <li><a href="coach.html" class="txt">Coaching</a></li>
                    <li><a href="programmes.html" class="txt">Produits</a></li>
                    <li><a href="galerie.html" class="txt">Galerie photos</a></li>
                    <li><a href="contact.html" class="txt">Contact</a></li>
                </ul>
            </div>
        </nav>
    </div>

    <div class="border-container">
        <div class="container-text">
            <h1 class="h1">Bienvenue chez <span style="color: #65bb00;">FAB H24</span> !</h1><br />
            <div class="text">
                Absorbés par le travail et la vie familiale, de nombreuses personnes éprouvent à l’heure actuelle des difficultés à trouver le temps et se motiver pour faire du sport.<br /><br />

                <span style="color: #65bb00;">FAB H24</span> vous accompagne pendant vos sessions de sport et vous aide à accomplir tous vos objectifs.<br /><br />

                Un programme complet et personnalisé mis au point par votre coach vous permet de travailler d’une façon précise et déterminée.<br /><br />

                Si vous souhaitez en savoir plus, n’hésitez pas à nous contacter.<br /><br />

                Cours individuels, cours collectifs, coaching d’entreprise, initiation au sport …découvrez la gamme de sports offerts par <span style="color: #65bb00;">FAB H24</span>.<br /><br /><br />
                Fabian
            </div>
        </div>
    </div>

    <footer class="footer">
        <div class="title-footer">
            <span style="color: #65bb00;">F</span>abian Galaz Harasic
        </div>
        <div class="text-footer">
            Rue du stock, 44 - 1200 Woluwe Saint-Lambert<br />
            fabian@h24.be<br />
            0488/48.01.05
        </div>
        <div>
            <ul>
                <li class="social-logo"><a href="#"><i class="fab fa-facebook-f fa-2x"></i></a></li>
                <li class="social-logo"><a href="#" class="nav-link"><i class="fab fa-instagram fa-2x"></i></a></li>
                <li class="social-logo"><a href="#" class="nav-link"><i class="far fa-envelope fa-2x"></i></a></li>
            </ul>
        </div>

    </footer>


</body>
</html>

最佳答案

阅读 CSS 中的评论

/*.footer {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    background-color: #24292e;
    color: rgba(255,255,255,0.75);
    text-align: center;
}----------------------------------------------- You dont have this class on your code! */ 

* {
    box-sizing: border-box;
}

html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100vh;
    font-family: Poppins;
    font-weight: 400;
    background: url(../images/background.jpg);
    background-position: center;
    background-size: cover;
    overflow-y: scroll;
}

nav {
    padding: 8px;
}

.logo {
    float: left;
    padding: 8px;
    margin-left: 16px;
}

    .logo a {
        color: #ffffff;
        text-transform: uppercase;
        font-weight: 700;
        font-size: 22px;
        letter-spacing: 0px;
        text-decoration: none;
    }

nav ul {
    float: right;
}

    nav ul li {
        display: inline-block;
        float: left;
    }

        nav ul li:not(:first-child) {
            margin-left: 48px;
        }

        nav ul li:last-child {
            margin-right: 24px;
        }

        nav ul li a {
            display: inline-block;
            outline: none;
            color: #000;
            text-transform: uppercase;
            text-decoration: none;
            font-size: 14px;
            letter-spacing: 1.2px;
            font-weight: 600;
        }

@media screen and (max-width: 864px) {
    .logo {
        padding: 0;
    }

    .nav-wrapper {
        position: fixed;
        top: 0px;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: -1;
        background: #fff;
        opacity: 0;
        transition: all 0.2s ease;
    }

        .nav-wrapper ul {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 100%;
        }

            .nav-wrapper ul li {
                display: block;
                float: none;
                width: 100%;
                text-align: right;
                margin-bottom: 10px;
            }

                .nav-wrapper ul li:nth-child(1) a {
                    transition-delay: 0.2s;
                }

                .nav-wrapper ul li:nth-child(2) a {
                    transition-delay: 0.3s;
                }

                .nav-wrapper ul li:nth-child(3) a {
                    transition-delay: 0.4s;
                }

                .nav-wrapper ul li:nth-child(4) a {
                    transition-delay: 0.5s;
                }

                .nav-wrapper ul li:not(:first-child) {
                    margin-left: 0;
                }

                .nav-wrapper ul li a {
                    padding: 10px 24px;
                    opacity: 0;
                    color: #000;
                    font-size: 14px;
                    font-weight: 600;
                    letter-spacing: 1.2px;
                    transform: translateX(-20px);
                    transition: all 0.2s ease;
                }

    .nav-btn {
        position: fixed;
        right: 10px;
        top: 10px;
        display: block;
        width: 48px;
        height: 48px;
        cursor: pointer;
        z-index: 9999;
        border-radius: 50%;
    }

        .nav-btn i {
            display: block;
            width: 20px;
            height: 2px;
            background: #ffffff;
            border-radius: 2px;
            margin-left: 14px;
        }

            .nav-btn i:nth-child(1) {
                margin-top: 16px;
            }

            .nav-btn i:nth-child(2) {
                margin-top: 4px;
                opacity: 1;
            }

            .nav-btn i:nth-child(3) {
                margin-top: 4px;
            }
}

#nav:checked + .nav-btn {
    transform: rotate(45deg);
}

    #nav:checked + .nav-btn i {
        background: #000;
        transition: transform 0.2s ease;
    }

        #nav:checked + .nav-btn i:nth-child(1) {
            transform: translateY(6px) rotate(180deg);
        }

        #nav:checked + .nav-btn i:nth-child(2) {
            opacity: 0;
        }

        #nav:checked + .nav-btn i:nth-child(3) {
            transform: translateY(-6px) rotate(90deg);
        }

#nav:checked ~ .nav-wrapper {
    z-index: 9990;
    opacity: 1;
}

    #nav:checked ~ .nav-wrapper ul li a {
        opacity: 1;
        transform: translateX(0);
    }

.hidden {
    display: none;
}

.txt {
    color:white;
    font-size:16px;
}

.container {
    margin-top: 1%;
}

.border-container {
    background-color: rgba(0, 0, 0, 0.7);
    margin-top: 7%;
    margin-bottom:1%;
    margin-left: 15%;
    margin-right: 15%;
    padding: 5px;
    border-radius: 5px;
    max-height: 690px;

}

.container-text {
    margin-top: 1%;
    margin-bottom: 1%;
    margin-left: 1%;
    margin-right: 1%;
    padding: 1%;
    border-radius: 3px;
}

.text {
    font-size: 14px;
    color: white;
}

.h1 {
    color: white;
}

.logo-herbalife {
    height: 50px;
    width: 50px;
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 5%;
}

.social-logo {
    list-style: none;
    padding-right: 30px;
    display: inline;
    margin-right:11px;
}

.fab {
    color: white;
}

.far {
    color: white;
}
* {
    margin: 0;
}

.active, .btn:hover {
    border-bottom: 2px solid #65bb00;
}
.blockquote-footer {
    background-color: rgba(0, 0, 0, 0.7);
    /*position: absolute; -------------------- If you want your footer remains at the button of your page */
    left: 0;
    bottom: 0;
    width: 100%;
    text-align: center;
    padding: 5px 0 5px 0;
    clear: both;
}
.well
{
    position: relative;
}
.title-footer {
    color: white;
    font-weight: 700;
    font-size: 22px;
}

.text-footer {
    margin: 0 0 12px 0;
    color: white;
    font-weight: 600;
    font-size: 11px;
}

.gallery {
    background-color: rgba(0, 0, 0, 0.7);
    margin-top: 7%;
    margin-bottom: 4%;
    margin-left: 15%;
    margin-right: 15%;
    padding: 10px;
    border-radius: 3px;
    text-align: center;
}

.gallery img{
    transition: 0.7s;
    padding: 10px;
    width: 300px;
    height: 300px;
}

.gallery img:hover{
    filter: grayscale(50%);
    transform: scale(1.1);
}

/*.ifooter
{
    margin-bottom: -60px;
} ------------------------------ You dont need any margins*/
.topnav a:hover {
    border-bottom: 5px solid #65bb00;
    padding-bottom: 8px;
    transition: all 0.3s linear;
    -webkit-transition: all 0.3s linear;
    -moz-transition: all 0.3s linear;
}

.topnav a.active {
   border-bottom: 5px solid #65bb00;
   padding-bottom:8px;
}
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Accueil - Fab h24</title>
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link href="https://fonts.googleapis.com/css?family=Poppins&display=swap" rel="stylesheet">
    <script src="https://kit.fontawesome.com/6d0f7aa58c.js" crossorigin="anonymous"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body class="body">
    <div class="container">
        <nav>
            <input type="checkbox" id="nav" class="hidden">
            <label for="nav" class="nav-btn">
                <i></i>
                <i></i>
                <i></i>
            </label>
            <div class="logo">
                <a href="index.html"><span style="color: #65bb00;">N</span>ame</a>
            </div>

            <div id="myDIV" class="nav-wrapper topnav">
                <ul>
                    <li><a href="index.html" class="txt active">Home</a></li>
                    <li><a href="coach.html" class="txt">Coaching</a></li>
                    <li><a href="programmes.html" class="txt">Produits</a></li>
                    <li><a href="galerie.html" class="txt">Galerie photos</a></li>
                    <li><a href="contact.html" class="txt">Contact</a></li>
                </ul>
            </div>
        </nav>
    </div>

    <div class="border-container">
        <div class="container-text">
            <h1 class="h1">Bienvenue chez <span style="color: #65bb00;">NAME</span> !</h1><br />
            <div class="text">
                Absorbés par le travail et la vie familiale, de nombreuses personnes éprouvent à l’heure actuelle des difficultés à trouver le temps et se motiver pour faire du sport.<br /><br />

                <span style="color: #65bb00;">NAME</span> vous accompagne pendant vos sessions de sport et vous aide à accomplir tous vos objectifs.<br /><br />

                Un programme complet et personnalisé mis au point par votre coach vous permet de travailler d’une façon précise et déterminée.<br /><br />

                Si vous souhaitez en savoir plus, n’hésitez pas à nous contacter.<br /><br />

                Cours individuels, cours collectifs, coaching d’entreprise, initiation au sport …découvrez la gamme de sports offerts par <span style="color: #65bb00;">NAME</span>.<br /><br /><br />
                NAME
            </div>
        </div>
    </div>

    <!--<div>
        <img class="logo-herbalife" src="images/herbalife.png" />
    </div>-->



    <footer class="blockquote-footer text-center ifooter" id="footer">
        <div class="title-footer">
            <span style="color: #65bb00;">N</span>ame
        </div>
        <div class="text-footer">
            Street, 44 - 1000 Brussels<br />
            info@email.be<br />
            0111/11.11.11
        </div>
        <div>
            <ul>
                <li class="social-logo"><a href="#"><i class="fab fa-facebook-f fa-2x"></i></a></li>
                <li class="social-logo"><a href="#" class="nav-link"><i class="fab fa-instagram fa-2x"></i></a></li>
                <li class="social-logo"><a href="#" class="nav-link"><i class="far fa-envelope fa-2x"></i></a></li>
            </ul>
        </div>

    </footer>


</body>
</html>

关于html - 页脚 html 也显示在下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59737984/

上一篇:javascript - 使用倒计时使图像在页面中居中并响应

下一篇:html - CSS扩展div的宽度以覆盖左侧的div

相关文章:

html - CSS 填充剩余的水平空间并显示省略号

javascript - 图像图标直到我悬停在它上面才出现? - CSS/JS 问题 - 添加事件小部件

javascript - 如何使用最接近js的选择器

css - 文字装饰 : underline vs border-bottom

html - :checked css not working

jquery - 谷歌浏览器 : css ('text-decoration' ) returns "extra" values

javascript - 标记模板文字混淆

javascript - 链接到外部页面上的特定位置

html - Chrome 16 网络套接字 hybi-17

javascript - 创建一个带有内部滚动条的可拖动、可调整大小的 div 容器