【问题标题】:My div content gets overlapped by the next div when i switch to small devices当我切换到小型设备时,我的 div 内容与下一个 div 重叠
【发布时间】:2021-08-26 19:15:52
【问题描述】:

我正在使用引导程序,当我切换到小型设备时,我的内容会与下一个 div 重叠。我试图更改所有内容并将边距放在 div 的底部,但似乎没有任何效果。我错过了一些东西。我不确定它是否与我尝试添加的相关药水有关,因此我可以在每个 div 的底部添加我的 svg。

HTML

<div class="container-fluid  vh-100 " id="projects">
  <!-- <div class="container d-flex h-100 " id="pwrap"> -->
    <div class="row align-items-center mx-auto " id="cards">
      <div class="col-sm-6 col-lg-4 ">
        <div class="card" >
          <img src="pics/project1.jpg" class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-primary">Go somewhere</a>
          </div>
        </div>
      </div>

      <div class=" col-sm-6 col-lg-4  ">
        <div class="card" >
          <img src="pics/project1.jpg" class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-primary">Go somewhere</a>
          </div>
        </div>
      </div>

      <div class="col-sm-6 col-lg-4  ">
        <div class="card">
          <img src="pics/project1.jpg" class="card-img-top" alt="...">
          <div class="card-body">
            <h5 class="card-title">Card title</h5>
            <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
            <a href="#" class="btn btn-primary">Go somewhere</a>
          </div>
        </div>
      </div>
    </div>
    <svg class="botp" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="#FFB9B9" fill-opacity="1" d="M0,192L48,165.3C96,139,192,85,288,96C384,107,480,181,576,218.7C672,256,768,256,864,245.3C960,235,1056,213,1152,218.7C1248,224,1344,256,1392,272L1440,288L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>
  <!-- </div> -->
</div>

<!-- /projects -->

<!-- contact -->

<div class="container-fluid  w-100 vh-100 my-auto  d-flex justify-content-center align-items-center " id="contact">
  <!--Section: Contact v.2-->

  <div id="border-shadow">

<div class="border border-success p-3" id="bordercustom">

    <section class="mb-4 " id="formcustom">

      <!--Section heading-->
      <h2 class="h1-responsive font-weight-bold text-center my-4">Contact Me</h2>

      <div class="row justify-content-center">

          <!--Grid column-->
          <div class="col-md-9 mb-md-0 mb-5">
              <form id="contact-form" name="contact-form" action="mail.php" method="POST">

                  <!--Grid row-->
                  <div class="row">

                      <!--Grid column-->
                      <div class="col-md-6">
                          <div class="md-form mb-0">
                              <input type="text" id="name" name="name" class="form-control">
                              <label for="name" class="">Your name</label>
                          </div>
                      </div>
                      <!--Grid column-->

                      <!--Grid column-->
                      <div class="col-md-6">
                          <div class="md-form mb-0">
                              <input type="text" id="email" name="email" class="form-control">
                              <label for="email" class="">Your email</label>
                          </div>
                      </div>
                      <!--Grid column-->

                  </div>
                  <!--Grid row-->

                  <!--Grid row-->
                  <div class="row">
                      <div class="col-md-12">
                          <div class="md-form mb-0">
                              <input type="text" id="subject" name="subject" class="form-control">
                              <label for="subject" class="">Subject</label>
                          </div>
                      </div>
                  </div>
                  <!--Grid row-->

                  <!--Grid row-->
                  <div class="row">

                      <!--Grid column-->
                      <div class="col-md-12">

                          <div class="md-form">
                              <textarea type="text" id="message" name="message" rows="2" class="form-control md-textarea"></textarea>
                              <label for="message">Your message</label>
                          </div>

                      </div>
                  </div>
                  <!--Grid row-->

              </form>

              <div class="text-center text-md-left d-flex justify-content-center">
                <a class="button mt-3" onclick="validateForm();">
    <span class="default">Send</span>
    <span class="success">Sent</span>
    <div class="left"></div>
    <div class="right"></div>
</a>

              </div>
              <div class="status"></div>
          </div>
          <!--Grid column-->



        </div>
      </div>

  </section>
  <!--Section: Contact v.2-->

</div>
<svg class="botc"xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="#363C62" fill-opacity="1" d="M0,288L60,272C120,256,240,224,360,224C480,224,600,256,720,277.3C840,299,960,309,1080,293.3C1200,277,1320,235,1380,213.3L1440,192L1440,320L1380,320C1320,320,1200,320,1080,320C960,320,840,320,720,320C600,320,480,320,360,320C240,320,120,320,60,320L0,320Z"></path></svg>
</div>


<!-- /contact -->

还有我的css

#home,
#about,
#projects,
#contact{
  position: relative;
}

 #projects .botp{
   z-index: 1;
   position: absolute;
   bottom: 0;
   left:0;
 }
 #cards{
   z-index: 2;
 }
 #contact .botc{
   position: absolute;
   bottom: 0;
   left:0;
 }

【问题讨论】:

    标签: html css overlap bootstrap-5 overlapping


    【解决方案1】:

    你用的是什么浏览器?我已经运行了你的代码,它没有重叠(我使用的是 Opera/Google Chrome)。

    另外,您可以将 height: auto 添加到部门div,这可能会有所帮助:)

    编辑:

    (我终于明白你的意思了)

    只需使用z-index。代码如下:

    CSS

    #home,
    #about,
    #projects,
    #contact {
      position: relative;
    }
    
     #projects .botp {
       z-index: 1;
       bottom: 0;
       left: 0;
       position: absolute;
     }
    
     #contact {
         z-index: 10;
     }
    
     #projects {
         z-index: 10;
     }
    
    .botc{
       position: absolute;
       z-index: 1;
       left: 0;
       bottom: 200px;
     }
    
     #card-text {
         z-index: 10000;
     }
    
    .botp {
        position: absolute;
        z-index: 1;
        left: 0;
        bottom: 500px;
         z-index: 1;
     }
    
     .col-md-6 {
         z-index: 10;
     }
    

    index.html

    <!DOCTYPE html>
    <html>
    
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    
    <body>
    
        <div class="container-fluid  vh-100 " id="projects">
            <!-- <div class="container d-flex h-100 " id="pwrap"> -->
            <div class="row align-items-center mx-auto " id="cards">
                <div class="col-sm-6 col-lg-4 ">
                    <div class="card">
                        <img src="pics/project1.jpg" class="card-img-top" alt="...">
                        <div class="card-body">
                            <h5 class="card-title">Card title</h5>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of
                                the card's content.</p>
                            <a href="#" class="btn btn-primary">Go somewhere</a>
                        </div>
                    </div>
                </div>
    
                <div class="col-sm-6 col-lg-4">
                    <div class="card">
                        <img src="pics/project1.jpg" class="card-img-top" alt="...">
                        <div class="card-body">
                            <h5 class="card-title">Card title</h5>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of
                                the card's content.</p>
                            <a href="#" class="btn btn-primary">Go somewhere</a>
                        </div>
                    </div>
                </div>
    
                <div class="col-sm-6 col-lg-4">
                    <div class="card">
                        <img src="pics/project1.jpg" class="card-img-top" alt="...">
                        <div class="card-body">
                            <h5 class="card-title" style="z-index: 10;">Card title</h5>
                            <p class="card-text">Some quick example text to build on the card title and make up the bulk of
                                the card's content.</p>
                            <a href="#" class="btn btn-primary">Go somewhere</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <svg class="botp" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320">
            <path fill="#FFB9B9" fill-opacity="1"
                d="M0,192L48,165.3C96,139,192,85,288,96C384,107,480,181,576,218.7C672,256,768,256,864,245.3C960,235,1056,213,1152,218.7C1248,224,1344,256,1392,272L1440,288L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z">
            </path>
        </svg>
            <!-- </div> -->
        
    
        <!-- /projects -->
    
        <!-- contact -->
    
        <div class="container-fluid  w-100 vh-100 my-auto  d-flex justify-content-center align-items-center " id="contact">
            <!--Section: Contact v.2-->
    
            <div id="border-shadow">
    
                <div class="border border-success p-3" id="bordercustom">
    
                    <section class="mb-4 " id="formcustom">
    
                        <!--Section heading-->
                        <h2 class="h1-responsive font-weight-bold text-center my-4">Contact Me</h2>
    
                        <div class="row justify-content-center">
    
                            <!--Grid column-->
                            <div class="col-md-9 mb-md-0 mb-5">
                                <form id="contact-form" name="contact-form" action="mail.php" method="POST">
    
                                    <!--Grid row-->
                                    <div class="row">
    
                                        <!--Grid column-->
                                        <div class="col-md-6">
                                            <div class="md-form mb-0">
                                                <input type="text" id="name" name="name" class="form-control">
                                                <label for="name" class="">Your name</label>
                                            </div>
                                        </div>
                                        <!--Grid column-->
    
                                        <!--Grid column-->
                                        <div class="col-md-6">
                                            <div class="md-form mb-0">
                                                <input type="text" id="email" name="email" class="form-control">
                                                <label for="email" class="">Your email</label>
                                            </div>
                                        </div>
                                        <!--Grid column-->
    
                                    </div>
                                    <!--Grid row-->
    
                                    <!--Grid row-->
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div class="md-form mb-0">
                                                <input type="text" id="subject" name="subject" class="form-control">
                                                <label for="subject" class="">Subject</label>
                                            </div>
                                        </div>
                                    </div>
                                    <!--Grid row-->
    
                                    <!--Grid row-->
                                    <div class="row">
    
                                        <!--Grid column-->
                                        <div class="col-md-12">
    
                                            <div class="md-form">
                                                <textarea type="text" id="message" name="message" rows="2"
                                                    class="form-control md-textarea"></textarea>
                                                <label for="message">Your message</label>
                                            </div>
    
                                        </div>
                                    </div>
                                    <!--Grid row-->
    
                                </form>
    
                                <div class="text-center text-md-left d-flex justify-content-center">
                                    <a class="button mt-3" onclick="validateForm();">
                                        <span class="default">Send</span>
                                        <span class="success">Sent</span>
                                        <div class="left"></div>
                                        <div class="right"></div>
                                    </a>
    
                                </div>
                                <div class="status"></div>
                            </div>
                            <!--Grid column-->
    
    
    
                        </div>
                </div>
    
                </section>
                <!--Section: Contact v.2-->
    
            </div>
            
        </div>
    
    
        <!-- /contact -->
        <svg class="botc" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320">
            <path fill="#363C62" fill-opacity="1"
                d="M0,288L60,272C120,256,240,224,360,224C480,224,600,256,720,277.3C840,299,960,309,1080,293.3C1200,277,1320,235,1380,213.3L1440,192L1440,320L1380,320C1320,320,1200,320,1080,320C960,320,840,320,720,320C600,320,480,320,360,320C240,320,120,320,60,320L0,320Z">
            </path>
        </svg>
    </body>
    
    </html>
    

    希望这会有所帮助:)

    【讨论】:

    • 嘿,谢谢你的帮助!但不幸的是,它不起作用。我的问题是我的#projects div 没有扩展以覆盖我的内容,并且最终重叠。我也尝试添加 heigh:auto 。
    【解决方案2】:

    所以我只是通过在 css 上添加此代码来随机修复它

    .card-img-top {
        width: 100%;
        height: 15vw;
        object-fit: cover;
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 2020-09-12
      • 2013-05-10
      • 2023-04-03
      相关资源
      最近更新 更多