【问题标题】:Flexbox Form not covering entire siteFlexbox 表单未覆盖整个站点
【发布时间】:2021-07-07 01:40:04
【问题描述】:

碰巧我的“表单”有 3 个 div “(.contact-in)”,我在我的 css 中用“:nth-child”来称呼它们,而使用 flex 我确实控制了它们在网站上的百分比,但在 x-轴。所以我的问题是我如何控制它们在 y 轴上的百分比,因为它们没有覆盖整个网站,例如我的页脚不会一直向下,因为我没有用内容覆盖整个页面。

后记:网站布局采用css网格。

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-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 - 8901</p>
                    <p>011 - 1234 - 5678</p>
                    <h2><i class="fa fa-envelope" aria-hidden="true"></i>Email</h2>
                    <p>asd@asdfgh.com.ar</p>
                    <p>asd@asdfgh.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(3, auto);
}
.contenedor .contenedor-nav{
    grid-column-start: 1;
    grid-column-end: 4;
}
.contenedor .contenedor-form{
    grid-column: span 2;
}
.contenedor .contenedor-footer{
    grid-column-start: 1;
    grid-column-end: 4;
}
/* MENU NAVEGACION*/
nav{
    position: sticky;
    top: 0;
    z-index: 30;
}
.menu-navegacion{    
    width: 100%;
    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;        
}
/* FORM */
.contact-wrap{
    width: 100%;
    height: auto;
    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%;    
}
@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%;        
    }
}
/* FOOTER */
#footer{
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgb(54, 54, 54);    
    height: 80px;
    width: 100%;
}
#footer p{
    color: white;
    font-weight: 400;
    font-family: 'Ubuntu', sans-serif;
    padding: 5px;
    border-bottom: solid white 1px;
}

【问题讨论】:

    标签: html jquery css flexbox css-grid


    【解决方案1】:

    首先将htmlbodyheight 设置为100%

    html, body{
        height: 100%;
    }
    

    如果要将页脚高度设置为80px,则将其设置为contenedor

    .contenedor{
        ...
        grid-template-rows: repeat(2, auto) 80px;
    }
    

    当您可以使用grid-template-rows 使用grid 控制高度时,为什么要在内部设置高度80px

    #footer{
        ...
        height: 80px; // Should be avoided as per your design
        ...           // instead add height for whole footer in grid-tempate-rows
    }
    

    * {
      padding: 0;
      margin: 0;
      box-sizing: border-box;
    }
    
    html,
    body {
      height: 100%;
    }
    
    body {
      font-family: 'Poppins', sans-serif;
      background: #fff;
    }
    
    
    /*GRID CONTENEDOR*/
    
    .contenedor {
      height: 100%;
      width: 100%;
      margin: 0 auto;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      grid-template-rows: repeat(2, auto) 80px;
    }
    
    .contenedor .contenedor-nav {
      grid-column-start: 1;
      grid-column-end: 4;
    }
    
    .contenedor .contenedor-form {
      grid-column: span 2;
    }
    
    .contenedor .contenedor-footer {
      grid-column-start: 1;
      grid-column-end: 4;
    }
    
    
    /* MENU NAVEGACION*/
    
    nav {
      position: sticky;
      top: 0;
      z-index: 30;
    }
    
    .menu-navegacion {
      width: 100%;
      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;
    }
    
    
    /* FORM */
    
    .contact-wrap {
      width: 100%;
      height: auto;
      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%;
    }
    
    @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%;
      }
    }
    
    
    /* FOOTER */
    
    #footer {
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: rgb(54, 54, 54);
      height: 80px;
      width: 100%;
    }
    
    #footer p {
      color: white;
      font-weight: 400;
      font-family: 'Ubuntu', sans-serif;
      padding: 5px;
      border-bottom: solid white 1px;
    }
    <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-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 - 8901</p>
            <p>011 - 1234 - 5678</p>
            <h2><i class="fa fa-envelope" aria-hidden="true"></i>Email</h2>
            <p>asd@asdfgh.com.ar</p>
            <p>asd@asdfgh.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>

    【讨论】:

    • 将 html 和 body 的高度设置为 100% 不起作用。您还有其他想法吗?
    • 不只是高度,我添加了更多代码和解释
    猜你喜欢
    • 1970-01-01
    • 2012-09-23
    • 2012-07-05
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多