Split div with diagonal line

前端 未结 3 1307
[愿得一人]
[愿得一人] 2021-01-15 18:35

How would you split a div into 2 parts (both containing horizontal text) by a diagonal line?

e.g. see this where 1 has a rectangular background image and 2 has text

3条回答
  •  旧时难觅i
    2021-01-15 19:08

    As per my knowledge, its cannot be done using any single CSS property directly, you will have to hack it via using pseudo-elements, or best approach will be do it using SVG

    .container {
      width: 90%;
      margin: 0 auto;
    }
    .box {
      width: 200px;
      height: 150px;
      text-align: center;
    }
    .box-1 {
      background: #ff6347;
    }
    .box-2 {
      background: #0ff;
    }
    .box-2:before {
      display: inline-block;
      margin: 0;
      margin-top: -30px;
      margin-left: -30px;
      content: '';
      border: 30px solid transparent;
      border-right: 200px solid #0ff;
    }
    TITLE 1

提交回复
热议问题