You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HTML/CSS作品集项目:Footer与Main内容重叠问题求助

解决Footer与Main内容重叠问题

问题描述

我正在学习HTML和CSS,制作迷你作品集项目时遇到Footer重叠Main内容的问题。尝试调整main的内边距、宽度无效;给body添加height、display:flex和flex-direction属性后问题仍未解决。页面在75%缩放时显示正常,100%缩放时出现重叠。

项目代码

Index.html

<!DOCTYPE html>
<html lang="pt-br">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Portfólio</title>
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Krona+One&family=Montserrat:ital,wght@0,600;1,400&display=swap" rel="stylesheet">
</head>

<body>
    <header>
    </header>

    <main class="main">
        <section class="main__texto">
            <h1 class="main__texto__titulo">Eleve seu negócio digital a outro nível <strong class="DestaqueTitulo">com um Front-end de qualidade!</strong></h1>
            <h4 class = "main__texto__paragrafo">Olá! Sou Joana Santos, desenvolvedora Front-end com especialidade em React, HTML e CSS. Ajudo pequenos
                negócios e designers a colocarem em prática boas ideias. Vamos conversar?</h4>
            <div class="main__link">

                <h3 class="main__link__texto">Acesse minhas redes:</h3>

                <a 
                    class="main__link__botao" href="https://github.com" target="_blank">
                    <img src="./assets/github.png" alt="Logo do github">
                    Github
                </a>

                <a 
                    class="main__link__botao" href="https://www.linkedin.com" target="_blank">
                    <img src="./assets/linkedin.png" alt="Logo do linkendin">
                    Linkedin
                </a>

                <a 
                    class="main__link__botao" href="https://www.twitch.tv" target="_blank">
                    <img src="./assets/twitch.png" alt="Logo da twitch">
                    Twitch
                </a>
            </div>
            
        </section>
        <img class="main__imagem" src="./assets/Imagem.png">
    </main>
    <footer class="rodape">
        <p>Desenvolvido por Luan Ribeiro</p>
    </footer>
</body>

</html>

style.css

* {
    margin: 0;
    padding: 0;
}


body {
    box-sizing: border-box;
    background-color: #000;
    color: #F6F6F6;
    height: 100vh;
    display  : flex;
    flex-direction: column;

}

.DestaqueTitulo {
    color: #22D4FD;
}

.main {
    flex: 1;
    padding: 5% 15%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    min-height: 100vh;
}

.main__texto {
    width: 615px;
    height: 482px;
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.main__texto__titulo {
    color: #F6F6F6;
    font-family: 'Krona One', sans-serif;
    font-size: 36px;
    font-style: normal;
    font-weight: 400;
    line-height: 56px;
}

.main__texto__paragrafo {
    color: #F6F6F6;
    font-family: 'Montserrat', sans-serif;
    font-size: 24px;
    font-style: normal;
    font-weight: 400;
    line-height: 36px;
}

.main__imagem {
    width: 488px;
    height: 550px;
    flex-shrink: 0;
}

.main__link {
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    align-items: center;
    gap : 32px
}

.main__link__texto {
    color: #F6F6F6;
    text-align: center;
    font-family: "Krona One", sans-serif;
    font-size: 24px;
    font-style: normal;
    font-weight: 400;
    line-height: 40px; 
}

.main__link__botao {
    display: flex;
    justify-content: center;
    gap : 16px;
    width: 378px;
    text-align: center;
    gap: 16px;
    border-radius: 8px;
    border: 2px solid #22D4FD;
    font-family: 'Montserrat', sans-serif;
    font-size: 24px;
    font-style: normal;
    font-weight: 600;
    padding: 21px 0;
    text-decoration: none;
    color: #F6F6F6;
    line-height: 36px;
}

.main__link__botao:hover {
    border-radius: 8px;
    border: 2px solid #22D4FD;
    background: #272727;
}


.rodape{
    padding: 24px;
    color: #000000;
    background-color: #22D4FD;
    text-align: center;
    font-family: 'Montserrat', sans-serif;
    font-size: 24px;
    font-weight: 400;
    margin-top: auto;
}

解决方案

问题根源

  1. body 设置固定 height:100vh,限制了页面总高度,当main内容实际高度超过视口高度时,footer会被挤压重叠;
  2. .main 同时设置 flex:1 和 min-height:100vh,加上内外边距后,main实际高度会超出body的限制;
  3. .main__texto 固定了 height:482px,在内容溢出或屏幕尺寸变化时,会破坏布局结构。

修改步骤

  1. 将 body 的 height:100vh 改为 min-height:100vh,让页面能根据内容自动扩展高度;
  2. 移除 .main 中的 min-height:100vh,依赖 flex:1 让它占据body的可用空间;
  3. 删除 .main__texto 中的 height:482px,让内容自然撑开容器。

修改后的CSS代码

* {
    margin: 0;
    padding: 0;
}

body {
    box-sizing: border-box;
    background-color: #000;
    color: #F6F6F6;
    min-height: 100vh; /* 修改为min-height */
    display: flex;
    flex-direction: column;
}

.DestaqueTitulo {
    color: #22D4FD;
}

.main {
    flex: 1;
    padding: 5% 15%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
    /* 移除min-height:100vh */
}

.main__texto {
    width: 615px;
    /* 移除height:482px */
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.main__texto__titulo {
    color: #F6F6F6;
    font-family: 'Krona One', sans-serif;
    font-size: 36px;
    font-style: normal;
    font-weight: 400;
    line-height: 56px;
}

.main__texto__paragrafo {
    color: #F6F6F6;
    font-family: 'Montserrat', sans-serif;
    font-size: 24px;
    font-style: normal;
    font-weight: 400;
    line-height: 36px;
}

.main__imagem {
    width: 488px;
    height: 550px;
    flex-shrink: 0;
}

.main__link {
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    align-items: center;
    gap: 32px
}

.main__link__texto {
    color: #F6F6F6;
    text-align: center;
    font-family: "Krona One", sans-serif;
    font-size: 24px;
    font-style: normal;
    font-weight: 400;
    line-height: 40px; 
}

.main__link__botao {
    display: flex;
    justify-content: center;
    gap: 16px;
    width: 378px;
    text-align: center;
    border-radius: 8px;
    border: 2px solid #22D4FD;
    font-family: 'Montserrat', sans-serif;
    font-size: 24px;
    font-style: normal;
    font-weight: 600;
    padding: 21px 0;
    text-decoration: none;
    color: #F6F6F6;
    line-height: 36px;
}

.main__link__botao:hover {
    border-radius: 8px;
    border: 2px solid #22D4FD;
    background: #272727;
}

.rodape{
    padding: 24px;
    color: #000000;
    background-color: #22D4FD;
    text-align: center;
    font-family: 'Montserrat', sans-serif;
    font-size: 24px;
    font-weight: 400;
    margin-top: auto;
}

内容的提问来源于stack exchange,提问作者Luan Ribeiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 21:14:52