create ribbon with css

后端 未结 2 761
北荒
北荒 2021-01-23 02:19

I have sidebar menu finally created. now I need create ribbon on selected item like show image (red) (I need really gray color ribbon). But I don\'t want use image background an

2条回答
  •  攒了一身酷
    2021-01-23 02:32

    this will have to be adapted to your needs, but something using pseudo elements would make this possible:

    .box{
      height:300px;
      width:300px;
      box-shadow:inset 0 0 15px #222;
      position:relative;
      margin:0 auto;
      background:gray;
      }
    
    .active{
      position:absolute;
      top:30px;
      left:-5%;
      height:30px;
      width:105%;
      background:tomato;
      border-radius: 5px 0 0 0;
      }
    .active:before{
      content:"";
      position:absolute;
      height:16px;
      top:5px;
      left:0;
      width:100%;
      border-top:2px dashed red;
      border-bottom:2px dashed red;
      }
    .active:after{
      content:"";
      position:absolute;
      right:-10px;
      height:20px;
      width:20px;
      top:5px;
      background:tomato;
      border-radius: 0 5px 0 0;
      transform:rotate(45deg);  
      }
    .active a{
      position:absolute;
      top:0;
      left:0;
      height:100%;
      width:100%;
      text-align:center;
      display:inline-block;
      text-decoration:none;
      line-height:30px;
      }
    .active a:after{
      content:"";
      position:absolute;
      bottom:-15px;
      left:6px;
      height:30px;
      width:30px;
      background:darkred;;
      transform:rotate(45deg);  
      z-index:-2;
      }


    note

    the transform property will require prefixes as well.

提交回复
热议问题