How to create a custom shape - css

前端 未结 3 2078
悲哀的现实
悲哀的现实 2020-12-17 05:04

I would like to create a custom shape like this image :

\"enter

how can I do ?

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 05:56

    • Add the background color to the parent div to fill in the gap
    • Place the border-radius on the parent div to create the two rounded corners
    • Move the :before and :after down slightly with top: 20px so they don't peak out the top of the div

    Example

    Here is a fiddle of the below:

    #chevron {
      width: 350px;
      height: 100px;
      background: #337AB7;
      border-radius: 10px 10px 0 0;
      position: relative;
    }
    #chevron:before {
      content: '';
      position: absolute;
      top: 20px;
      left: 0;
      height: 100%;
      width: 51%;
      background: #337AB7;
      -webkit-transform: skew(0deg, 6deg);
      -moz-transform: skew(0deg, 6deg);
      -ms-transform: skew(0deg, 6deg);
      -o-transform: skew(0deg, 6deg);
      transform: skew(0deg, 6deg);
    }
    #chevron:after {
      content: '';
      position: absolute;
      top: 20px;
      right: 0;
      height: 100%;
      width: 50%;
      background: #337AB7;
      -webkit-transform: skew(0deg, -6deg);
      -moz-transform: skew(0deg, -6deg);
      -ms-transform: skew(0deg, -6deg);
      -o-transform: skew(0deg, -6deg);
      transform: skew(0deg, -6deg);
    }

提交回复
热议问题