Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap text content inside a clip path polygon(triangle) shape and image clipped on other half

Im trying to achieve something like this enter image description here

I need to display some text and an image in two halves like shown in the above image. Tried to use clip-path ,but the text content is not wrapped and have issues with alignment too.

My code:

.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>
like image 350
Yashwanth Chowdary Kata Avatar asked Jun 25 '21 13:06

Yashwanth Chowdary Kata


People also ask

How do you clip the path of a picture?

CSS clip-path Editor When using mouse, hold down Shift to lock x-axis or Alt to lock y-axis. Hold down shift while selecting a preset to only update animation-preview clip-path.

What is clip path property?

The clip-path CSS property creates a clipping region that sets what part of an element should be shown. Parts that are inside the region are shown, while those outside are hidden.


Video Answer


1 Answers

You need shape-outside here:

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

You can reduce the code like below:

.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>
like image 88
Temani Afif Avatar answered Oct 19 '22 09:10

Temani Afif