【问题标题】:CSS Grid layout not covering the entire websiteCSS 网格布局不覆盖整个网站
【发布时间】:2021-07-07 18:41:51
【问题描述】:

我的问题是我的 CSS 网格布局没有覆盖整个网站,因此例如我的页脚并没有一直向下。我不知道是什么问题,所以我需要一些帮助。谢谢你。 This is how it looks like my grid. See below the footer that there is a blank space

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../css/contact.css">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&family=Ubuntu:wght@300&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" crossorigin="anonymous">
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
    <title>TRV ECOLOGICO SRL</title>
</head>
<body>
    <div class="contenedor">
        <nav class="contenedor-nav">
            <div class="menu-navegacion">
                <div class="logo">
                    <div class="contenedor-triangulo">                    
                        <div class="triangulo"></div>
                    </div>
                    <div class="contenedor-texto">
                        <div class="textotriangulo"><h2>TRV ECOLOGICO SRL</h2></div>
                    </div>                
                </div>
                <div class="menu-lista">
                    <ul>
                        <li><a href=index.html>INICIO</a></li>
                        <li><a href=#>PRODUCTOS</a></li>
                        <li><a href=#>EMPRESA</a></li>
                        <li><a href=contact.html>CONTACTO</a></li>
                    </ul>
                </div>
            </div>
        </nav>
        <div class="contenedor-section">
            <div class="main">
                <h2>Estamos para ayudarlo</h2>
            </div>
        </div>
        <div class="contenedor-form">
            <div class="contact-wrap">
                <div class="contact-in">
                    <h1>Información de Contacto</h1>
                    <h2><i class="fa fa-phone" aria-hidden="true"></i>Teléfono</h2>
                    <p>123 - 4567 - 8911</p>
                    <p>123 - 4567 - 8911</p>
                    <h2><i class="fa fa-envelope" aria-hidden="true"></i>Email</h2>
                    <p>asd@asdfghi.com.ar</p>
                    <p>asdtas@asdfhi.com.ar</p>
                    <h2><i class="fa fa-map-marker" aria-hidden="true"></i>Dirección</h2>
                    <p>Morón, Buenos Aires, Argentina</p>
                </div>
                <div class="contact-in">
                    <h1>Contacto</h1>
                    <form>
                        <input type="text" placeholder="Nombre Completo" class="contact-in-input">
                        <input type="text" placeholder="Nombre Completo" class="contact-in-input">
                        <input type="text" placeholder="Nombre Completo" class="contact-in-input">
                        <textarea placeholder="Mensaje" class="contact-in-textarea"></textarea>
                        <input type="submit" value="SUBMIT" class="contact-in-btn">
                    </form>
                </div>
                <div class="contact-in">
                    <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d52502.855079198634!2d-58.65170330080583!3d-34.6691347508206!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x95bcc76f57e3be01%3A0xa488fcdcec5b600f!2sMor%C3%B3n%2C%20Provincia%20de%20Buenos%20Aires!5e0!3m2!1ses!2sar!4v1618120836940!5m2!1ses!2sar" width="100%" height="auto" style="border:0;" allowfullscreen="" loading="lazy"></iframe>
                </div>
            </div>
        </div>
        <footer class="contenedor-footer">
            <div id="footer">
                <p>TRV ECOLOGICO SRL - Todos los derechos reservados</p>
            </div>
        </footer>
    </div>
</body>

CSS:

*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;  
}
body{
    font-family: 'Poppins', sans-serif;
    background: #fff;
}
/*GRID CONTENEDOR*/
.contenedor{
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(4, auto);
    grid-template-areas: "nav nav"
                         "section section"
                         "form form"
                         "footer footer";    
}
.contenedor .contenedor-nav{
    /*grid-column-start: 1;
    grid-column-end: 3;*/
    grid-area: nav;
}
.contenedor .contenedor-section{
    /*grid-column-start: 1;
    grid-column-end: 3;*/
    grid-area: section;
}
.contenedor .contenedor-form{
    /*grid-column-start: 1;
    grid-column-end: 3;*/
    grid-area: form;
}
.contenedor .contenedor-footer{
    /*grid-column-start: 1;
    grid-column-end: 3;*/
    grid-area: footer;
}
/* MENU NAVEGACION */
nav{
    position: sticky;
    top: 0;
    z-index: 30;
}
.menu-navegacion{
    margin: auto;
    overflow: hidden;
    padding: 0;
    display: flex;    
    height: 80px;
    justify-content: space-between;
    align-items: center;
    background-color: rgb(54, 54, 54);
}
.logo{
    padding-right: 10%;
    padding-left: 10%;
    height: 50px;
    width: 20%;
    display: flex;
    justify-content: center;
    margin-left: 1%;
    position: relative;
}
.contenedor-triangulo{
    height: 100%;
    position: absolute;
}
.triangulo{
    height: 0%;
    width: 0%;
    border-right: 30px solid transparent;
    border-left: 30px solid transparent;
    border-bottom: 50px solid red;
    display: block;
}
.contenedor-texto{
    display: flex;
    align-items: center;
    justify-content:center;
    height: 50px;
    width: 100%;
}
.textotriangulo{
    position: absolute;
    font-weight: 700;
    color: rgb(255, 255, 255);
    font-size: 1em;
    text-shadow: 3px 2px 1px rgba(54, 54, 54, 0.493);
}
.menu-lista{
    margin-right: 20%;
}
.menu-lista ul li{
    list-style: none;
    display: inline-block;    
}
.menu-lista ul li a{
    text-decoration: none;
    color: white;
    padding-left: 20px;        
}
/* SECTION */
.contenedor-section{
    display: flex;
    justify-content: center;
    line-height: center;
    align-items: center;
    height: 275px;
    background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
.main{
    font-size: 3em;
    color: whitesmoke;
    text-shadow: 3px 2px 3px #000000;
    font-weight: 900;
}
/* FORM */
.contact-wrap{
    margin: auto;
    display: flex;
    flex-wrap: wrap;
}
.contact-in{
    padding: 40px 30px;
}
.contact-in:nth-child(1){
    flex: 30%;
    background: url(../images-form/1.jpg);
    color: #fff;
}
.contact-in:nth-child(2){
    flex: 45%;
    background: #c31432;
}
.contact-in:nth-child(3){
    flex: 25%;
    padding: 0;
}
.contact-in h1{
    font-size: 24px;
    color: #fff;
    text-transform: uppercase;
    font-weight: 500;
}
.contact-in h2{
    font-size: 20px;
    font-weight: 400;
    margin-bottom: 15px;
}
.contact-in h2 i{
    font-size: 16px;
    width: 40px;
    height: 40px;
    margin-right: 10px;
    background: #f5f5f5;
    color: #000;
    border-radius: 50px;
    line-height: 40px;
    text-align: center;
}
.contact-in p{
    font-size: 14px;
    font-weight: 300;
    margin-bottom: 20px;
}
.contact-in form{
    width: 100%;
    height: auto;
}
.contact-in-input{
    width: 100%;
    height: 40px;
    margin-bottom: 20px;
    border: 1px solid #fff;
    outline: none;
    padding-left: 5px;
    color: #fff;
    font-size: 12px;
    font-weight: 300;
    font-family:'Poppins', sans-serif;
}
.contact-in-textarea{
    width: 100%;
    height: 140px;
    margin-bottom: 20px;
    border: 1px solid #fff;
    outline: none;
    padding-top: 5px;
    padding-left: 5px;
    color: #fff;
    font-size: 12px;
    font-weight: 300;
    font-family:'Poppins', sans-serif;
}
.contact-in-btn{
    width: 100%;
    height: 40px;
    border: 1px solid #fff;
    outline: none;
    font-size: 12px;
    font-weight: 300;
    font-family:'Poppins', sans-serif;
    cursor: pointer;
}
.contact-in iframe{
    width: 100%;
    height: 100%;    
}
/* FOOTER */
#footer{
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgb(54, 54, 54);    
    height: 80px;
}
#footer p{
    color: white;
    font-weight: 400;
    font-family: 'Ubuntu', sans-serif;
    padding: 5px;
    border-bottom: solid white 1px;
}
/* RESPONSIVE */
@media only screen and (max-width:480px){
    .contact-in:nth-child(1){
        flex: 50%;        
    }
    .contact-in:nth-child(2){
        flex: 50%;        
    }
    .contact-in:nth-child(3){
        flex: 100%;        
    }
}
@media only screen and (max-width:360px){
    .contact-in:nth-child(1){
        flex: 50%;        
    }
    .contact-in:nth-child(2){
        flex: 50%;        
    }
    .contact-in:nth-child(3){
        flex: 100%;        
    }
}
@media screen and (max-width: 768px){
    .contenedor{
        grid-template-areas: "nav nav"
                            "section"
                            "form form"
                             "footer footer";  
    }
}

【问题讨论】:

  • grid-template-rows: repeat(2, auto) 1fr auto;min-height: 100vh;,假设您的第三行具有可变高度并包含您的页面内容。
  • 看起来不错,但现在我的网格表单区域中有一个空白区域。我怎样才能让它完成整行?现在看起来像这样:ibb.co/b63GZCJ
  • 我解决了这个问题。在我的主容器中明确地min-height: 100vh; 帮助我覆盖整个网页。但是后来我的表格行出现了这个问题,它没有覆盖整行。所以我检查了我的 html,发现我的 form-container 中有一个子容器,其属性应该在他的父容器中。我的其他父容器也发生了同样的事情,例如我在footer-container 有一个带有高度属性的 chil 容器。然后我删除所有这些子容器,并将属性放在每个容器的相应容器中。

标签: html jquery css flexbox css-grid


【解决方案1】:

我刚刚找到了解决办法。

尽量不要直接给section设置高度,在grid-template-columns中设置。

.contenedor {
    grid-template-rows: 8vh 23vh 60vh 9vh; /* this should sum 100 */
  }
  .contenedor-form {
    align-self: center;
  }
  .contenedor-section {
    /* height: 275px; */ /* remove property */
  }
  .menu-navegacion {
    height: 100%;
  }
  #footer {
    height: 100%;
  }

【讨论】:

    猜你喜欢
    • 2014-10-02
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2011-05-24
    • 2014-01-18
    • 2012-09-24
    • 1970-01-01
    • 2011-10-16
    相关资源
    最近更新 更多