【问题标题】:Bootstrap 3 card-wide responsiveness to different screen sizesBootstrap 3 卡片范围对不同屏幕尺寸的响应能力
【发布时间】:2020-06-22 02:57:07
【问题描述】:

我创建了一个 Bootstrap 3 卡片宽度,并将 div class="card-wide-image-wrap" 设置为 50% 的最小宽度。这可以确保在我的笔记本电脑上正确显示(否则它不会显示带有覆盖文本块的完整图像)。但是,div 的最小宽度为 50% 会破坏卡片在手机上的显示方式(下图)。有没有办法解决这个问题?

第二个问题:对于右边添加的每一行文本,左边的图像似乎变大了。能否以某种方式将图像与卡片的文本侧分开以使其保持固定?

下图是 PC/大屏幕上想要的结果。当我将 div min-width 设置为 50% 时,我得到了这个。

但是,如下图所示,这在手机上显示效果不佳: 如果我省略 div min-width 50%,我会在 PC/大屏幕上得到以下不需要的结果:

但是,它会在移动设备上正确显示:

这是我的代码。谢谢瑞克:

 <style>

 p {
 color: white;
 }

 h2.ex1 {

 padding-left: 30px;
 }

 ul.ex1 {

 padding-left: 60px;
 }

 p.ex1 {

 padding-left: 30px;
 }

 h6.ex2{

 font-size: 22px;
 }


 .text-block {
  position: absolute;
  bottom: 80px;
  right:370px;

  background-color: #292929;
  color: white;
  padding-left: 20px;
  padding-right: 20px;
  block-size: max-content;

  }

  .cover {
  object-fit: cover;
  width: 10px;
  height: 10px;
  }


   div img{
   min-width:100%;
   min-height:100%;
   height:auto;
   position:relative;
   top:50%;
   left:50%;
   transform:translateY(-50%) translateX(-50%);
   }

   </style>



   <p style="text-align: center;"><br></p><div><div class="col-xs-12">
   <div class="calcite-web">
      <div class="card-base card-wide" style="background: #292929;max-width: 100%; margin: 0 auto;">
   
        <div class="card-wide-image-wrap" style="min-width:50%">
          <img alt="hurricanes" class="card-wide-image cover img-fluid" src="#">
             <div class="text-block">
               <h6 class="ex2" style="text-align: left; color: rgb(38, 149, 188);">Naturkræfter</h6> 
               <p style="text-align: left; color: rgb(38, 149, 188);">Cykloner i den nordlige og 
                sydlige hemisfære, adskilt af ækvator, hvor corioliskraften er 0,&nbsp; &nbsp;og 
                derfor forhindrer hvirvelvindene i at formes og krydse ækvatorlinjen</p>
             </div>
 
         </div>



         <div class="card-content px-2">
          <h2 class="ex1" style="color: white" id="intro">Lorem Ipsum</h2>
           <br>
          <p class="ex1">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 
            tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud 
            exercitation ullamco laboris nisi ut aliquip ex ea</p>
             <br>
               <ul class="ex1" style="color: white">
                 <li>Duis aute irure dolor in </li>
                 <li>Eprehenderit in voluptate velit esse cillum </li>
                 <li>Dolore eu fugiat nulla pariatur</li>
                 <li>Excepteur sint occaecat cupidatat non proident</li>
                 <li>Csunt in culpa qui</li>
                 </ul>
                 <br>
 
                  <p><a href="#" class="btn btn-primary" style="min-width: 114px; margin-left: 25px" 
                      target="_blank">Send os en besked</a></p>
                   <br>
        
             </div>
          </div>
       </div>
    </div>
</div>

【问题讨论】:

    标签: css responsive-images bootstrap-cards


    【解决方案1】:

    您提到您使用的是 Bootstrap 3,但您的 img 标签使用 img-fluid 类,而它应该使用 img-responsive 类。

    <img alt="hurricanes" class="card-wide-image cover img-responsive" src="#">
    

    另外,我认为你的卡片范围的 CSS 定义是由某个模板驱动的? Bootstrap3 本身就没有卡片并使用面板。

    【讨论】:

    • 感谢您指出这一点。我已将其更改为 img-responsiveness,但问题仍然存在,因为图像包装器设置为 50% 的最小值。但是,您也是对的,我采用了一个模板并对其进行了调整-我认为这是一个 Bootstrap 模板-但我刚刚意识到它是 ESRI 基于 Bootstrap 3 的自定义主题的模板,所以也许我是把我的问题发错地方了?!我对 css、html 等的世界还很陌生,所以我还在摸索中
    • 如果您使用 img-responsive 类,请避免 img 标签的任何外部 CSS。对于您的情况,如果没有对模板使用的 CSS/JS 的引用,很难进行调试。此外,如果 img-fluid 类来自模板,他们可能已经在某个地方定义了它,或者他们可能正在使用 bootstrap4。
    • 谢谢,很高兴知道 - 并且可能刚刚为我节省了很多时间 :)
    猜你喜欢
    • 2022-11-21
    • 1970-01-01
    • 2019-11-15
    • 1970-01-01
    • 2017-08-22
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 1970-01-01
    相关资源
    最近更新 更多