【问题标题】:How can I make this Bootstrap 4 code more responsive?如何使此 Bootstrap 4 代码更具响应性?
【发布时间】:2018-01-30 04:14:11
【问题描述】:

我正在尝试让此代码的响应更加灵敏,但我一直未能找到好的解决方案。

随着浏览器窗口向移动设备尺寸缩小,列表变得非常狭窄,右侧的图片/视频项目变得非常小且不美观。我认为这部分是由于我无法将右侧的图片/视频项目移到中心列下方,该项目包含所有项目符号以允许向右扩展更多。

随着网站变小,我希望所有元素都占据屏幕的全宽(当然是默认填充)。本质上,这意味着包含视频播放器和卡通的最右侧列将移动到其左侧的条目下方。像这样的东西:,而不是上面的代码目前在移动设备中的样子:。在桌面上保留这种外观:

<section id="about">
     <div class="container">
       <h3 class="font-weight-bold text-center">Discovering The Future.                        </h3>
         <div class="row mt-4">

         </div>
         <div class="row">
             <div class="col">
                <div class="row">                
                    <div class="col-auto">       
                        <img src="https://picsum.photos/140/65" alt="" class="img-fluid testphoto">
                    </div>
                    <div class="col pt-3">
                        <h2>The Cao Lab</h2>
                        <h3 class="font-weight-bold pt-1 pb-3">April 2016 - Present</h3>
                        <ul>
                            <li class="pb-3">Employ alkene metathesis to produce porous molecules valuable for encapsulation and adsorption applications</li>
                            <li class="pb-3">Prepare analytical samples, preform characterization analysis, and interpret results for molecules of interest</li>
                            <li class="pb-3">Communicate research to others by attending conferences and poster presentations</li>
                            <li class="pb-5">Devised a cost-effective method to quantify hydrogen production during evolution experiments</li>
                        </ul>
                    </div>
                    <div class="col-sm-3 ">

                            <div class="embed-responsive embed-responsive-5by3 teensie">
                              <iframe class="embed-responsive-item youtube" src="https://www.youtube.com/embed/KPZ8HHRR1A0"></iframe></div>    
                     </div>
                </div>            
             </div>

         </div>
         <div class="row">
             <div class="col">
                 <div class="row">
                     <div class="col-auto">
                         <img src="https://picsum.photos/140/65" alt="" class="img-fluid testphoto">
                     </div>
                     <div class="col pt-3">
                         <h2>Institut Parisien de Chimie Moléculaire
                            </h2>
                         <p class="text-primary">National Science Foundation Internation REU Program.</p>
                         <h3 class="font-weight-bold pb-3">May 2017 - August 2017</h3>
                         <ul>
                             <li class="pb-3">Conduct study on the selective deprotection of perbenzylated a-cyclodextrin to access novel functionalization</li>
                             <li class="pb-3">Synthesize molecules suitable as ligands in metal-catalysis and for improving chiral HPLC discrimination ability</li>
                             <li class="pb-3">Prepare analytical samples, preform characterization analysis, and interpret data of cyclodextrin derivatives</li>
                             <li>Submitted abstract to present at the Chemical Education Division of the 255th ACS National Meeting</li>
                         </ul>                           
                     </div>
                     <div class="col-sm-3 ">
                            <img src="https://vignette.wikia.nocookie.net/rayman/images/c/cf/Teensy.png" alt="" class="img-fluid teensie2 ">
                            </div>
                     </div>

                 </div>

             </div>

         </div>

 </section>

CSS:

        .shift{
        margin-left:20px;
    }

    .barbie{
      list-style: none;
        margin: 0;
        padding: 0;
    }

    .barbieitem{
      //text-align: right;
      font-size: 1.3em;
    }
    .testphoto { 
      display: inline-block; 
      vertical-align:middle;
   }

    .joblist{
      display: inline-block;
    }

    .labname{
      display: inline-block; 
      vertical-align:middle;
      border:solid black 1px; 
    }

    .youtube {
      max-width: 300px;
      max-height: 300px;
      position: relative !important;
      float: right;

    }

    .teensie{
      top: 50%;
      left:50%;
      transform: translate(-50%,-50%);
    }

    .teensie2{
      position: relative;
      top: 50%;
      left:50%;
      transform: translate(-50%,-50%);
    }

【问题讨论】:

  • 您尝试过什么来实现更好的响应能力?您的代码不建议您使用或尝试使用任何额外的断点。我也不清楚为什么你的这么多列是嵌入在网格中的网格的一部分?
  • 实际上,这是一个修改后的脚手架解决方案,作为对我之前的一个问题的回答,我被指示作为一个单独的问题提出:/ 相反。相关操作:stackoverflow.com/questions/48491026/…
  • 这与上一个问题有关实际上使这个问题不太合适,尤其是考虑到您提供的代码并未表明已尝试寻找解决方案。
  • 我确实尝试了几种解决方案,这是“最好的”。我试着避免提出一个新问题,然后我因为没有提出一个新问题而被骂。现在我提出了一个新问题,而你叫我提出一个新问题,没有人提供有用的答案,所以....抱歉,但伪善很多吗?
  • 你称之为虚伪......但实际上任何人都想要一个明确的问题。您提供的 HTML 不是一个最小示例,您拒绝回答为什么它也不会尝试您希望它做的任何事情……而是通过引用先前提出的问题来转移注意力。我会尽快为您的结构提交一个潜在的解决方案,但我会鼓励您考虑如何在未来更好地提出问题和回应批评。

标签: html css twitter-bootstrap bootstrap-4 twitter-bootstrap-4


【解决方案1】:

据我了解,您希望每组 image | content | image/video 以一种响应更友好的方式折叠,这样当您在较小的设备上查看内容时,所有内容都易于阅读。

解决方案几乎完全取决于您如何实现 Bootstrap Grid,并且可能会简化您的布局。查看您提供的结构,您似乎没有使用container-fluid,尽管表明您想要占据整个宽度,并且您还在可能不需要嵌套网格的情况下使用嵌套网格。

由于每个部分由 3 列组成,这些列在较小的屏幕上折叠成全宽,我们可以将此视为每个 row 是您的内容的包装器的场景。在下面的代码 sn-p 中,我设置了以下结构:

  1. 所有 3 列默认为 12 宽。
  2. 第 1 列在中等断点处缩小到 3 宽(或更大)
  3. 第 2 列在中等断点处缩小到 5 宽(或更大)
  4. 第 3 列在中等断点处缩小到 4 宽(或更大)

此时您的基本结构已布局...在小屏幕上,所有内容都是全宽的,而在更大的屏幕上,您将开始在一行中看到所有 3 个内容元素。从这里开始,只需添加一些额外的 BS 实用程序类来帮助正确渲染所有内容:

  • 添加align-items-center mb-4 会使项目彼此垂直居中对齐,并增加每个row 之间的下边距。
  • mb-3 mb-md-0 添加到第一列可确保在较小的屏幕上每个图像下方都有填充。
  • pb-2 添加到您的&lt;ul&gt; 并将最后一个pb-5 更改为pb-3 允许您实现相同的填充,同时更容易以编程方式填充这些列表项。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="container-fluid">
  <div class="row">
    <div class="col-12">
      <h3 class="text-center">Page Title</h3>
    </div>
  </div>
  
  <!-- This is where each content group starts -->
  <div class="row align-items-center mb-4">
    <div class="col-12 col-md-3 mb-3 mb-md-0 text-center">
      <img src="http://placehold.it/300x300" class="img-fluid" />
    </div>
    
    <div class="col-12 col-md-5">
        <h2>Section Title</h2>
        <h3 class="pt-1 pb-3">Date</h3>

        <ul class="pb-2">
        <li class="pb-3">List Item #1</li>
        <li class="pb-3">List Item #2</li>
        <li class="pb-3">List Item #3</li>
        <li class="pb-3">List Item #4</li>
        </ul>
    </div>
        
    <div class="col-12 col-md-4">
      <div class="embed-responsive embed-responsive-16by9">
        <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/zpOULjyy-n8?rel=0" allowfullscreen></iframe>
      </div>
    </div>
  </div>
  <!-- This is where each content group ends -->
</div>

注意:您需要展开 sn-p 以查看其响应性质,因此可能不允许嵌入的 &lt;iframe&gt; 进行处理。将 sn-p 复制并粘贴到本地 HTML 文件中应该可以让您查看所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 2022-09-25
    • 2016-12-11
    相关资源
    最近更新 更多