【问题标题】:Bootstrap - Wrap text around image not workingBootstrap - 在图像周围环绕文本不起作用
【发布时间】:2022-01-18 23:01:13
【问题描述】:

我正在尝试在图像周围环绕文字,就像这个问题一样:

Wrap text around bootstrap image

我已经尝试了那里的所有解决方案,但都没有奏效。

这是我正在使用的布局:

div.col-md-6
    img.imagePost(src=`/{{{blogPost['feature-image-2']}}}`)
    | {{#if blogPost['feature-image-3'] == ""}}
    video.postVideo(controls)
        source(src=`/{{{blogPost['video']}}}`) 
    | {{else}}
    img.imagePost(src=`/{{{blogPost['feature-image-3']}}}`)
    | {{/if}}
    | {{#if blogPost['feature-image-4'] != ""}}
    img.imagePost(src=`/{{{blogPost['feature-image-4']}}}`)
    | {{/if}}
div(style=`float: none;`)
    | {{{blogPost['post']}}}

【问题讨论】:

  • 请发布实际呈现的 HTML(或代表性示例)而不是模板。
  • 但基本上你会将图像包装在具有float-leftfloat-start 类的容器中(请标记你的引导版本)。仅此一项就可以做到。

标签: css twitter-bootstrap


【解决方案1】:

如果您使用的是 bootstrap 3.3,请尝试在您的 jam/pug 文件中添加 pull-left 和 imagePost。您还可以使用 float none 删除最后一个包装 div。最终代码将如下所示。

div.col-md-6
  img.imagePost.pull-left(src=`/{{{blogPost['feature-image-2']}}}`)
  | {{#if blogPost['feature-image-3'] == ""}}
  video.postVideo(controls)
    source(src=`/{{{blogPost['video']}}}`) 
  | {{else}}
  img.imagePost.pull-left(src=`/{{{blogPost['feature-image-3']}}}`)
  | {{/if}}
  | {{#if blogPost['feature-image-4'] != ""}}
  img.imagePost.pull-left(src=`/{{{blogPost['feature-image-4']}}}`)
  | {{/if}}
  | {{{blogPost['post']}}}

【讨论】:

  • 我试过你的解决方案,第一段文字换行,但之后所有其他段落都在图片下方
  • 能否请您详细说明 blogPost['post'] 是返回字符串还是字符串中包含 html 标记
  • 字符串中包含html标签,所以它有大约10个段落标签
  • 检查这是否能解决您的问题。创建了一个虚拟变量以使字符串为 html codepen.io/prathap937/pen/rNGbzbd
  • 谢谢!这解决了我的问题
【解决方案2】:

我认为如果你创建单独的 CSS 类会很有用

看这个例子:

CSS:


.wrapper {
  column-count: 2;
  column-gap: 50px;
  padding: 50px;
}

p {
  line-height: 1.6; 
  font-family: Helvetica;
  text-align: justify;
  margin: 0;
  font-size: 14px;
}

.star {
  float: left;
  width: 250px;
  shape-outside: url(https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg);
  shape-margin:20px;
  margin-right: 20px;
  margin-bottom: 20px;
}

.moon {
  border-radius: 50%;
  height: 200px; 
  width:200px;
  background-color: #2badd9;
  float: right;
  shape-outside: inset(1% round 50%);
  margin-left: 20px;
  margin-bottom: 10px;
}

HTML

<div class="wrapper">
  
  <img src="https://upload.wikimedia.org/wikipedia/commons/3/34/Red_star.svg" alt="" class="star">
  
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use. </p>
  
  
  <div class="moon"></div>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use. </p>
</div>
    

结果会是这样的:

很难猜出问题的原因,因为您还没有共享整个 HTML,所以希望这个示例对您有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多