【问题标题】:Bootstrap grip in mobile view and Desktop view移动视图和桌面视图中的引导网格
【发布时间】:2018-06-03 10:10:04
【问题描述】:
<div class="container-fluid">
<div class="row">
   <div class="col-xs-8 col-md-8 col-sm-8">
      <img src="#"/>  
   </div>
   <div class="col-xs-4 col-md-4 col-sm-4">
      <blockquote>
         <p style="font-size:20px; color:black;">"I had never seen anything in the least like them before. A single look at them is enough to show that they could only be written by a mathematician of the highest class. They must be true because, if they were not true, no one would have the imagination to invent them."</p>
         <footer><cite>Anonymous</cite></footer>
      </blockquote>
   </div>
</div>

您好,在上面的代码中,我正在尝试将文本和图像并排显示,在桌面上查看时我得到了预期的输出,但在移动设备上查看时是同一页面我看到部分文本和图像重叠但相同在桌面视图中在移动设备中查看时页面正常。

如何将所有视图中的外观同步在一起?

任何指针都会有所帮助。

谢谢。

PS:我没有足够的代表来发布图片,所以在引号之间#'ing img src 值

【问题讨论】:

    标签: twitter-bootstrap grid bootstrap-4


    【解决方案1】:

    此答案仅适用于 Bootstrap 4。

    您的代码有两个问题。

    1. 您要链接的图片大于其容器的宽度。
    2. *-xs-* 类已删除。

    解决方案

    1. 添加.img-fluid 类以使图像响应。
    2. 分别使用col-8col-4 类而不是col-xs-8col-xs-4

    由于您的所有breakpoints 都相同,因此仅使用col-8col-4 就足够了。您最好删除其他 col-*-* 类。

    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/css/bootstrap.css" rel="stylesheet"/>
    <div class="container-fluid">
      <div class="row">
        <div class="col-8">
          <img class="img-fluid" src="https://upload.wikimedia.org/wikipedia/commons/5/51/Augusta_National_Golf_Club%2C_Hole_10_%28Camellia%29_-_cropped.jpg" />
        </div>
        <div class="col-4">
          <blockquote>
            <p style="font-size:20px; color:black;">"I had never seen anything in the least like them before. A single look at them is enough to show that they could only be written by a mathematician of the highest class. They must be true because, if they were not true, no one would have the
              imagination to invent them."</p>
            <footer><cite>Anonymous</cite></footer>
          </blockquote>
        </div>
      </div>

    运行代码 sn-p 或检查pen on Codepen

    【讨论】:

    • 感谢您的快速帮助。我尝试了您的两种解决方案。我仍然看到,当我通过手机查看页面时,我仍然看到图像和文本(引用)在 potrait 模式下相互重叠,但当我尝试在横向更改时不重叠。查看桌面站点的页面也与横向相同。我将如何解决它在肖像模式下的外观问题?谢谢。
    • @Pandora-Box 你有哪个版本的 iOS 或 Andriod?
    • 嗨,Mahan,我使用的是 android 8。
    • 好的。我刚刚在Andriod 8 电话上对此进行了测试。它工作正常。是否以隐私模式(Chrome 上的隐身模式)打开了您的网页?
    • 我在正常的私人模式下尝试过,都得到了相同的结果这是页面:codepen.io/premkrishnan/full/vjBROG
    【解决方案2】:

    此答案仅适用于 Bootstrap 3。

    根据上面的代码,我怀疑您的问题是您链接到的img 大于其容器的宽度。最简单的解决方法是使用 Bootstrap 的实用程序类.img-responsive向图像添加一些响应行为@

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    
    <div class="container-fluid">
      <div class="row">
        <div class="col-xs-8">
          <img src="http://placehold.it/800x800" class="img-responsive" />  
        </div>
    
        <div class="col-xs-4">
          <blockquote>
            <p style="font-size:20px; color:black;">"I had never seen anything in the least like them before. A single look at them is enough to show that they could only be written by a mathematician of the highest class. They must be true because, if they were not true, no one would have the imagination to invent them."</p>
            <footer><cite>Anonymous</cite></footer>
          </blockquote>
       </div>
    </div>

    在上面的代码中,我们有一个 800 像素的方形图像,但 imp-responsive 类总是将其 max-width 强制为其容器的 100%。

    对您的代码进行的另一项更改:如果它们的值相同,则无需指定其他断点。您的col-xs-8 col-sm-8 col-md-8 与仅使用col-xs-8 相同。

    【讨论】:

    • 那天你回答了我的一个问题,即 在 Bootstrap 4 中到处都删除了 -xs- 变体。我想知道col-xs-4col-xs-8是否被删除了?
    • 抱歉!我看到您使用 xs 并假设您使用的是 Bootstrap 3。是的,xs-* 已被贬值;只需使用col-4col-8
    • 感谢您的快速帮助。我尝试了您的两种解决方案。我仍然看到,当我通过手机查看页面时,我仍然看到图像和文本(引用)在 potrait 模式下相互重叠,但当我尝试在横向模式下更改它时不会重叠。查看桌面站点的页面也与横向相同。我将如何解决它在肖像模式下的外观问题?谢谢。
    猜你喜欢
    • 2020-11-30
    • 1970-01-01
    • 2015-08-05
    • 2021-12-04
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多