How to make half-square background in css

前端 未结 3 1999
感情败类
感情败类 2020-12-16 19:44

\"square

Is it possible to make in pure css background for half square like on the imag

相关标签:
3条回答
  • 2020-12-16 20:07

    You can use transform if you don't need to worry about old browser support.

    .container {
      position: relative;
      overflow: hidden;
      width: 100px;
    }
    .square {
      width: 100px;
      height: 100px;
      background-color: #E30606;
    }
    .overlay {
      width: 171px;
      height: 72px;
      background-color: #D0CBCB;
      -webkit-transform: rotate(225deg);
      -moz-transform: rotate(225deg);
      -ms-transform: rotate(225deg);
      transform: rotate(225deg);
    }
    <div class="container">
      <div class="square">
        <div class="overlay"></div>
      </div>
    </div>

    http://jsfiddle.net/hT9vP/13/

    0 讨论(0)
  • 2020-12-16 20:21

    If your divs have fixed sizes, you can use borders to make two triangles as described in How do CSS triangles work?:

    div{
      display:inline-block;
      border-top:100px solid red;
      border-right:100px solid grey;
      }
    <div></div>

    To make other sizes, colors, you need to tweak the border properties :

    div {
      display: inline-block;
    }
    div:nth-child(1) {
      border-right: 100px solid red;
      border-top: 100px solid grey;
    }
    div:nth-child(2) {
      border-left: 100px solid red;
      border-top: 100px solid grey;
    }
    div:nth-child(3) {
      border-right: 50px solid red;
      border-top: 100px solid grey;
    }
    div:nth-child(4) {
      border-right: 100px solid red;
      border-bottom: 50px solid grey;
    }
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>

    0 讨论(0)
  • 2020-12-16 20:24

    You can also try linear-gradient

    div {
      width: 200px;
      height: 200px;
      background: rgba(248, 80, 50, 1);
      background:linear-gradient(to bottom right,grey 50%,red 50%);
    }
    <div></div>

    0 讨论(0)
提交回复
热议问题