How to create triangle shape in the top-right angle of another div to look divided by border

后端 未结 3 781
夕颜
夕颜 2020-12-08 06:39

I want to create shape like on this picture:

\"shape\"

I created triangle shape like on this pic, and s

3条回答
  •  孤城傲影
    2020-12-08 07:13

    You could use a rotate pseudo element in conjunction to an overflow:hidden on the parent.

    From here you could position the pseudo to the top right using position:absolute and you should be good to go!

    div {
      height: 250px;
      width: 300px;
      background: lightgray;
      border-radius: 10px;
      border: 5px solid dimgray;
      position: relative;
      overflow: hidden;
      margin: 30px auto;
    }
    div:before {
      content: "";
      position: absolute;
      top: -60px;
      right: -60px;
      height: 100px;
      width: 100px;
      background: green;
      border: 5px solid dimgray;
      transform: rotate(45deg);
    }
    
    /***********FOR DEMO ONLY*******************/
    
    
    html, body {
        margin:0;
        padding:0;height:100%;
        vertical-align:top;overflow:hidden;
        background: rgb(79, 79, 79);
        background: -moz-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
        background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(79, 79, 79, 1)), color-stop(100%, rgba(34, 34, 34, 1)));
        background: -webkit-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
        background: -o-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
        background: -ms-radial-gradient(center, ellipse cover, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
        background: radial-gradient(ellipse at center, rgba(79, 79, 79, 1) 0%, rgba(34, 34, 34, 1) 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#4f4f4f', endColorstr='#222222', GradientType=1);
    }

提交回复
热议问题