在bootstrap 3上的图像周围换行文本

时间:2015-10-07 23:01:23

标签: css css3 twitter-bootstrap-3

我遇到了一个问题,就是在我的列上将文字包裹起来。 我有一个模板,它正在运行多个页面。一些图像不够长,所以它不能覆盖整个列... 我意识到他们有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>

6 个答案:

答案 0 :(得分:11)

使用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>

图像上可能需要一些边距,因此文本不会贴近图像

答案 1 :(得分:7)

这适合我。

<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>

答案 2 :(得分:1)

我在这个页面上有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-->

答案 3 :(得分:1)

这些都不适合我。我使用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>

答案 4 :(得分:0)

在Adobe Photoshop中仅向图像添加少量边距,然后使用img src="img/blog/image.png" class="pull-left,复制就绕着图像进行,而无需添加任何样式要容易得多。

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

答案 5 :(得分:-2)

但如果你想要你的文字和图像,那么这对你有帮助。

<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>