Search code examples
csscss-shapes

Keep the text from being cut off when using shape-inside with CSS div boxes


New to this. I checked out many resources, but I could not get this to work.

Objective: Keep the text from being cut off when using shape-inside with CSS div boxes.

Here is a link to the code that does not work.

http://jsfiddle.net/0u8tk7o5/

Thanks for helping me out.

.container {
  -webkit-clip-path: polygon(50% 0%, 100% 100%, 0 100%);
  shape-inside: polygon(50% 0%, 100% 100%, 0 100%);
  height: 200px;
  width: 400px;
  background-color: crimson;
}
    </style>
  </head>
<body>

<div class="container">
  <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."</p>
</div>

Solution

  • shape-inside doesn't seem to be implemented yet so you'd need to use shape-outside to achieve the effect you want. In your case you could achieve a triangular shape by specifying left and right bounding shapes that effectively create a triangle like this:

    .main {
      width: 500px;
      background-color: yellow;
    }
    .left,
    .right {
      width:50%;
      height:200px;
    }
    .left {
      -webkit-shape-outside: polygon(0% 0%, 100% 0%, 0% 100%);
      shape-outside: polygon(0% 0%, 100% 0%, 0% 100%);
      -webkit-clip-path: polygon(0% 0%, 100% 0%, 0% 100%);
      float: left;
      background-color: crimson;
    }
    .right {
      -webkit-shape-outside: polygon(0% 0%, 100% 0%, 100% 100%);
      shape-outside: polygon(0% 0%, 100% 0%, 100% 100%);
      -webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 100%);
      float: right;
      background-color: blue;
    }
    <div class="main">
    <div class="left"></div>
    <div class="right"></div>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
        dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    </div>
    

    This jsfiddle shows it: http://jsfiddle.net/g2rqa0uL/