【问题标题】:Wrap text content inside a clip path polygon(triangle) shape and image clipped on other half将文本内容包装在剪辑路径多边形(三角形)形状内,并将图像剪辑在另一半
【发布时间】:2021-09-08 21:17:23
【问题描述】:

我正在尝试实现这样的目标

我需要将一些文本和图像分成两半,如上图所示。 尝试使用 clip-path ,但文本内容未换行,对齐也有问题。

我的代码:

.clipped-text{
  width: 250px; height: 250px;
  background: #1e90ff;
  clip-path: polygon(0 100%, 100% 100%, 0 0);
  text-align: justify;
  position: absolute;

}

.clipped-image{
  width: 250px; height: 250px;
  background: #1e90ff;
  clip-path: polygon(100% 100%, 100% 0, 0 0);
  text-align: justify;
   position: absolute;

}
<div>
 <img class="clipped-image" src="https://homepages.cae.wisc.edu/~ece533/images/arctichare.png"/>
 <p class="clipped-text">
  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. 
</p>
</div>

【问题讨论】:

    标签: html css image word-wrap clip-path


    【解决方案1】:

    你需要 shape-outside 这里:

    .box {
      width: 300px;
      height: 300px;
      background: #1e90ff;
      text-align: justify;
    }
    
    .clipped-image {
      float:right;
      width: 100%;
      height: 100%;
      background: #1e90ff;
      shape-outside: polygon(100% 100%, 100% 0, 0 0);
      clip-path:     polygon(100% 100%, 100% 0, 0 0);
    }
    <div class="box">
      <img class="clipped-image" src="https://homepages.cae.wisc.edu/~ece533/images/arctichare.png" />
      <p class="clipped-text">
        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.
      </p>
    </div>

    你可以像下面这样减少代码:

    .clipped-text  {
      width: 300px;
      height: 300px;
      background: #1e90ff;
      text-align: justify;
    }
    
    .clipped-text:before {
      content:"";
      float:right;
      width: 100%;
      height: 100%;
      background: url(https://picsum.photos/id/1069/400/400) center/cover;
      shape-outside: polygon(100% 100%, 100% 0, 0 0);
      clip-path:     polygon(100% 100%, 100% 0, 0 0);
    }
    <p class="clipped-text">
        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.
      </p>

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 2020-09-22
      • 2021-03-10
      • 2022-08-03
      • 2021-03-14
      • 2016-06-28
      • 2016-08-03
      • 1970-01-01
      • 2015-01-10
      相关资源
      最近更新 更多