【问题标题】:Bootstrap why my page has a white bar in right side of my page引导为什么我的页面在我的页面右侧有一个白条
【发布时间】:2021-02-09 00:31:18
【问题描述】:

我正在尝试让我的引导登录页面对所有显示器都具有响应性,因此我开始使用媒体查询来适应 iPhone、iPad 和其他设备上的页面,但是当我使用手机时,会出现白色网页右侧的栏也显示了整个模板,就像缩小了一样,右侧的白色栏上有一些 h1 标签。我将向您展示我的代码,希望有人可以帮助我,我整天都被困在这里。我需要帮助。我是前端开发的新手,所以不要给我一些建议。

<template>
   <div class="container-fluid m-0 p-0">
      <nav class="navbar navbar-expand-lg navbar-custom">
         <a class="navbar-brand " href="http://exaple.com/">
         <img src="../assets/logo.png" width="40" height="40" class="d-inline-block align-top" alt="">
         example.com
         </a>
         <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav mr-auto">
               <li class="nav-item active">
                  <a class="nav-link" href="#sigUP" style="color:white;">Signin</a>
               </li>
               <li class="nav-item">
                  <a class="nav-link" href="#mission" style="color:white;">Mission</a>
               </li>
            </ul>
         </div>
      </nav>
      <div id="home-page" class="full-height p-4">
         <div class="container pt-500">
            <div class="row pb-6 pt-20">
               <div class="col-lg-6  my-auto ">
                  <div class="text-right text-down mb-3 d-block d-lg-none">
                     <h1 class ="text-color text-right text-down">Hello,</h1>
                     <h1 class="display-1 text-color text-right text-down">Betatester!</h1>
                  </div>
               </div>
               <div class="col-lg-6 my-auto pt-6">
                  <div class="text-right text-down mb-3 d-none d-lg-block">
                     <h1 class ="text-color text-right text-down">Hello,</h1>
                     <h1 class="display-1 text-color text-right text-down" >Betatester!</h1>
                  </div>
               </div>
            </div>
         </div>
      </div>
      <div id="about" class="bg-light p-3 p-md-5">
       <div class="container-fluid">
         <h1 class="display-1 text-color-about text-center"  >example.com is </h1>
         <div class="row">
            <div class="col-lg">
               <h1 class="ml-md-4 mr-md-4 text-left" >
                  the socialnetwork for you
               </h1>
               <h1 class="ml-md-4 mr-md-4 text-left text-color-about_p" >Freetime</h1>
               <img src="../assets/exam1.png" height="100">
               <img src="../assets/exam1.png" height="100">
               <img src="../assets/exam1.png" height="100">
            </div>
            <div class="col-lg">
               <img src="../assets/about.png" height="300" class="m-4">
            </div>
         </div>
        </div>
      </div>
      <div id="marketplace" class=" p-4">
       <div class="container-fluid">
         <div class="row">
            <div class="col-lg">
               <img src="../assets/marketplace.png" height="400">
            </div>
            <div class="col-lg">
               <h1 class="ml-md-4 mr-md-4 text-right" >
                  <h1 class="ml-md-4 mr-md-4 text-right text-color-about_m" >MARKETPLACE</h1>
                  where you can find all you need
               </h1>
            </div>
         </div>
        </div>
      </div>
      <div id="shops" class=" p-4">
       <div class="container-fluid">
         <div class="row">
            <div class="col-lg">
               <h1 class="ml-md-4 mr-md-4 text-left" >
                  the place where you can contact your
                  <h1 class="ml-md-4 mr-md-4 text-left text-color-about_s p-4" >FAVORITE </h1>
                  <h1 class="ml-md-4 mr-md-4 text-left text-color-about_p" >STORE</h1>
               </h1>
            </div>
            <div class="col-lg">
               <img src="../assets/shop.png" height="400">
            </div>
         </div>
        </div>
      </div>
      <div id="comp" class=" p-4">
       <div class="container-fluid">
         <div class="row">
            <div class="col-lg">
               <img src="../assets/comp.png" height="400">
            </div>
            <div class="col-lg">
               <h1 class="ml-md-4 mr-md-4 text-right" >
                  be
                  <h1 class="ml-md-4 mr-md-4 text-right text-color-about_m" >COMPETITIVE</h1>
                  blablablablablablablalbalba
               </h1>
            </div>
         </div>
        </div>
      </div>
      <div id="mission" class=" p-4">
       <div class="container-fluid">
         <div class="row">
            <div class="col-lg">
               <h1 class="ml-md-4 mr-md-4 text-left" style="display: inline-block" >
                  the 
                  <h1 class="ml-md-4 mr-md-4 text-left text-color-about_s" style="display: inline-block" > MISSION </h1>
               </h1>
               <h3 class="ml-md-4 mr-md-4 text-left">
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel dolor neque. Vivamus id ultrices nunc. Proin vulputate iaculis tortor ac rhoncus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus in lobortis diam, eu ullamcorper ante. Pellentesque sodales felis sit amet metus laoreet sodales. Proin auctor nulla vitae porta pretium. Nullam tempor blandit sem vitae finibus.
               </h3>
            </div>
            <div class="col-lg">
               <img src="../assets/mission.png" height="400">
            </div>
         </div>
        </div>
      </div>
      <div id="betatest" class=" p-3">
       <div class="container-fluid">
         <div class="row justify-content-center">
            <div class="col-lg">
            </div>
            <h1 class="ml-md-0 mr-md-0   text-center display-1">
               Why you'll be 
               <h1 class="ml-md-4 mr-md-4 text-center  text-color-about_b display-1">
                  Betatester?
               </h1>
            </h1>
         </div>
         <div class="row ">
            <div class="col-lg">
               <h1 class="ml-md-4 mr-md-4 text-center" style="font-size: 4em;">
                  be
                  <h1 class="ml-md-4 mr-md-4 text-center" style="display: inline-block; color:white;font-size: 4em;font-size: 1.2em">BETATESTER</h1>
                  helps us to make the best experience possible on example.com
               </h1>
            </div>
         </div>
        </div>
      </div>
      <div id="sigUP" class=" p-2">
       <div class="container-fluid">
         <div class="row justify-content-center pd-8">
            <div class="col-lg pd-8">
               <h1 class="ml-md-4 mr-md-4 text-center display-2">
                  Become
                  <h1 class="ml-md-4 mr-md-4 text-center text-color-about_sn display-4">
                     a BETATESTER
                  </h1>
               </h1>
            </div>
         </div>
         <div class="row justify-content-center pd-8">
            <div class="col-lg ">
               <img src="../assets/player.png">
               <div class="row justify-content-center pd-8">
                  <div class="col-lg ">
                     <a href="/#/signupPlayer" class="btn btn-primary btn-lg btn-custom align-self-end" role="button">Player</a>
                  </div>
               </div>
            </div>
            <div class="col-lg ">
               <img src="../assets/store.png">
               <div class="row justify-content-center pd-8">
                  <div class="col-lg ">
                     <a href="/#/signupStore" class="btn btn-primary btn-lg btn-customS " role="button">Store</a>
                  </div>
               </div>
            </div>
         </div>
        </div>
      </div>
      <div id="contact" class="p-5">
       <div class="container-fluid">
         <div class="row justify-content-center mt-3 mb-3">
            <div v-if="show_contact == true" class="col-lg-4" style="color:white">
               <h2>Hai una domanda?</h2>
               <p>Contact us!</p>
               <div v-if="contact_notice != ''" class="alert alert-warning">
                  there's a problem. {{contact_notice}}
               </div>
               <form @submit.prevent="sendContactMessage()">
                  <div class="form-group text-left ">
                     <input v-model="contact_email"
                        type="email"
                        class="form-control"
                        placeholder="............"
                        >
                     <textarea v-model="contact_message"
                        class="form-control mt-3"
                        placeholder="..........."
                        rows="5"
                        ></textarea>
                  </div>
                  <button type="submit" class="btn btn-primary">send</button>
               </form>
            </div>
            <div v-else>
               <h3>mail sent correctly!</h3>
               <p>thanks for contact us!.</p>
            </div>
         </div>
        </div>
      </div>
      <div id="footer" class=" p-4">
         <footer class="text-light p-4">
            <small>&copy; 2020,example</small>
         </footer>
      </div>
   </div>
</template>
<style scoped>
   #home-page {
   background-color: #ff9e0b;
   background: url('../assets/bg_mt.jpg') no-repeat center center;
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
   background-size: cover;
   }
   #about {
   min-height: 40vh;
   }
   #contact {
   background-color: #252223;
   }
   #marketplace {
   background-color: #ff9e0b;
   }
   #comp {
   background-color: #ff9e0b;
   }
   #footer {
   background-color: #252223;
   }
   #betatest {
   background-color: #ff9e0b;
   }
   .navbar-custom { 
   background-color:  #ff9e0b; 
   } 
   /* Modify brand and text color */ 
   .navbar-custom .navbar-brand, 
   .navbar-custom .navbar-text { 
   color: white !important;
   font-size: 1.5em !important; 
   }
   .text-color{
   color:white;
   font-family: 'Mountserrat',sans-serif;
   font-weight: 600;
   }
   .text-color-about{
   color:#ff9e0b;
   font-family: 'Mountserrat',sans-serif;
   font-weight: 600;
   }
   .text-color-about_p{
   color:#ff9e0b;
   font-family: 'Mountserrat',sans-serif;
   font-weight: 800;
   font-size: 4em !important;
   }
   .text-color-about_s{
   color:#ff9e0b;
   font-family: 'Mountserrat',sans-serif;
   font-weight: 800;
   font-size: 3em !important;
   }
   .text-color-about_m{
   color: white;
   font-family: 'Mountserrat',sans-serif;
   font-weight: 600;
   font-size: 3em !important;
   }
   .text-color-about_b{
   color:white;
   font-family: 'Mountserrat',sans-serif;
   align-self: center;
   font-weight: 800;
   font-size: 2em !important;
   }
   .text-color-about_sn{
   color:#ff9e0b;
   font-family: 'Mountserrat',sans-serif;
   align-self: center;
   font-weight: 800;
   font-size: 1em !important;
   }
   .bg-primary{
   color:#ff9e0b;
   }
   .bg-imgPlayer{
   contain: url(../assets/store-02.png);
   }
   .btn-customS{
   border-radius: 1rem;
   background-color: #f23838 !important;
   }
   .btn-custom{
   border-radius: 1rem;
   background-color: #ff9e0b !important;
   }
   @media (max-width: 576px) { 
   .navbar-custom {
   width:1152px; /* .... */
   }
   .navbar-custom {
   width:1152px; /* .... */
   }
   .about {
   width:1152px; /* .... */
   }
   .home-page {
   width:1152px; /* .... */
   }
   ....
   }
@media (max-width: 375px) { 
.navbar-custom {
         width: 375px;
        
}
.about {
          width:375px; /* .... */
}
.home-page {
          width:375px; /* .... */
}
.marketplace {
          width:375px; /* .... */
}
.shop {
          width:375px; /* .... */
}
.comp {
          width:375px; /* .... */
}
.mission {
          width:375px; /* .... */
}
.betatest {
          width:375px; /* .... */
}
.sigUP {
          width:375px; /* .... */
}
.contact {
          width:375px; /* .... */
}
.footer {
          width:375px; /* .... */
}
}
</style>

【问题讨论】:

  • 请把图片和代码贴在你认为出现问题的地方?
  • 我已经添加了图片并用箭头指示了条的位置。
  • 一个或多个元素在右侧溢出。两个选项。您可以使用 DevTools 找到有问题的元素并修复其宽度或其他行为(填充等),或者您可以使问题静音并将溢出-x 设置为隐藏并希望没有其他中断:) [您可以设置溢出-x :仅对手机隐藏...]
  • 感谢 avia,你拯救了我的一天 :)
  • @Loki00 很高兴我能帮上忙!如果有帮助,请随时将我的答案标记为已接受。干杯

标签: html css bootstrap-4 responsive-design responsive


【解决方案1】:

一个或多个元素在右侧溢出。 2个选项

  1. 您可以使用 DevTools 找到有缺陷的元素并修复其宽度或其他行为(填充等);或

  2. 您可以解决问题并将overflow-x设置为隐藏,希望没有其他问题[您可以设置overflow-x:hidden仅用于手机]

【讨论】:

    【解决方案2】:

    Bootstrap 4.3+ 引入了一个名为 Responsive Font Sizes 的新功能,而不是手动设置每个断点的字体大小。

    您可以按照说明打开它,然后您不必编写那么多媒体查询。事实上,如果您是新手,我强烈建议您学习 SASS/SCSS。您可以使用 SASS/SCSS 更轻松地自定义 Bootstrap。文档中有一个完整的部分theming

    此外,您永远不需要使用 Bootstrap 嵌套容器:

    <!-- <div class="container-fluid m-0 p-0"> -->
        <nav class="navbar navbar-expand-lg navbar-custom">
            ...
        </nav>
        <div id="home-page" class="full-height p-4">
            <div class="container pt-500">...</div>
        </div>
            ...
        <div id="footer" class=" p-4">
            ...
        </div>
    <!-- </div> -->
    

    我只是觉得你的代码中有很多地方可以清理/改进。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      相关资源
      最近更新 更多