【问题标题】:Wrap text around an image on bootstrap 3在引导程序 3 上将文本环绕在图像周围
【发布时间】:2019-09-23 23:44:28
【问题描述】:

我遇到了一个问题,即在我的专栏中将文字环绕在我的图片周围。 我有一个运行多个页面的模板。有些图像不够长,所以它无法覆盖整个专栏...... 我意识到它们位于 2 个不同的 div 中,但如果有人对此有解决方案,请告诉我。

如果您阅读并了解问题所在,您会发现它不是重复的......

这是我的代码的样子

    <div class="row" data-sf-element="Row">
  <div id="contentPlaceholder_C002_Col00" class="sf_colsIn col-md-6" data-sf-element="Column 1">
    <div>
      <div>
        <h2>Contrary to popular belief, Lorem Ipsum is not simply r</h2>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during th</p>
        <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during th</p>
      </div>
    </div>
  </div>
  <div id="contentPlaceholder_C002_Col01" class="col-md-6" data-sf-element="Column 2"> <img src="/images/default-source/careers/careers_1.jpg?sfvrsn=2" title="careers_1" alt="careers_1"> </div>
</div>

【问题讨论】:

标签: css twitter-bootstrap-3


【解决方案1】:

当使用 2 列时,文本永远不会环绕图像。

你应该把图片和文字放在一栏中,并把它填满。然后将文本和图像包装在一个 div 中并将它们浮动到左侧。这行中的一些东西(代码是一个示例,未经测试):

<div class="col-md-12">
   <div class="pull-left"><img src="YourImage.png"/></div>
   <div class="pull-left">Your text goes here......</div>
</div>

您可能需要在图像上留一些边距,这样文字就不会紧贴图像

【讨论】:

  • 是的,谢谢您的回复。我想,但认为可能有办法克服这个问题。
【解决方案2】:

这对我有用。

<div class="col-md-12">
<img src="img/image.jpg" class="pull-left">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste molestiae aliquam optio mollitia, unde quas eaque voluptatem dignissimos eos maiores magni reprehenderit nisi, corrupti nemo hic id cum quasi officiis!</p>
</div>

【讨论】:

    【解决方案3】:

    这些都不适合我。我使用 rails 5.2 和 bootstrap 4.1 的工作代码:

    <div class="row">
      <div class="col">
        <img src="<%=url_for(@user.image)%>" class="float-left" style="height:150px;margin-right:10px">
           <p>A bunch of text</p>
           <p>More text</p>
      </div>
    </div>
    

    【讨论】:

    • 这实际上是2020年的正确答案。以前的正确答案显然不再有效。看起来“向左拉”现在是“向左浮动”。
    【解决方案4】:

    我在这个页面上有 2 列,每列都有一个文本环绕的图像、一个标题、副标题、文本和链接。我将图像嵌套在文本列中自己的列中以包装文本。此代码在移动设备上显示时转换为全列宽。如果你愿意,我相信你可以向右拉,但这对我有用。请参阅http://www.lbch.org/_Employment.html 的实际代码。

    <div class="container">
      <div class="row">
        <div class="col-xs-12">Page Head Title & Text</div>
        <div class="col-xs-12 col-md-6">
          <div class="col-xs-12 col-md-5">
            <img src="image" class="img-responsive" alt=""/> <br> 
          </div>
          <div class="text-left">
            <h4 class="text-center">
                <strong>Article Title</strong><br>
                <small>Article sub-title</small>
            </h4>
            <p>Text</p>
            <p><a href="link">link text</a><strong> </p>
          </div>
        </div>
        <div class="col-xs-12 col-md-6">
          <div class="col-xs-12 col-md-5">
            <img src="image" class="img-responsive" alt=""/> <br> 
          </div>
          <div class="text-left">
            <h4 class="text-center">
              <strong>Article Title</strong><br>
              <small>Article sub-title</small>
            </h4>
            <p>Text</p>
            <p><a href="link">link text</a><strong> </p>
          </div>
        </div>
      </div> <!--row-->
    </div> <!--container-->
    

    【讨论】:

    • 你可以在lbch.org/_Employment.html看到这个代码。我绝对不擅长我的工作,但这让我的老板很开心,这让我很开心!哈哈
    • 请不要在没有父行的情况下将列放在列中!这是无效的。看看link
    【解决方案5】:

    在 Adob​​e Photoshop 中为图像添加小边距要容易得多,然后使用 img src="img/blog/image.png" class="pull-left 复制围绕图像流动,而无需添加任何样式。

    我只是在图像的左侧和底部添加了一个 10px 的空白区域。

    【讨论】:

      【解决方案6】:

      但是,如果您希望文本和图像并排,那么这将对您有所帮助。

      <div class="row">
      <p class="col-md-8">Text goes here....</p>
      <img class="img-circle col-md-4" src="image goes here..." alt="image text">
      </div>
      

      【讨论】:

      • 这种粗略的解决方案只是将元素彼此相邻排列,但不要将文本包裹在图像周围 OP 要求的内容。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      相关资源
      最近更新 更多