Draw double curved item with beveled edges

前端 未结 4 1581
半阙折子戏
半阙折子戏 2021-01-14 01:16

I\'m creating a website, with a header / menu on top. In the middle, there is a logo. To accentuate this, I\'ve absolute positioned an ellips below the logo: So underneath,

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-14 01:27

    SVG would be the way to go for such things but for a CSS solution I would probably use multiple background with linear/radial-gradient BUT the drawback is that it can be difficult to calculate the different values and make the whole shape responsive.

    Here is an example that can help you get some idea:

    body {
      background:grey;
    }
    
    .header {
      border: 5px solid red;
      border-top: none;
      height: 100px;
      width: 600px;
      background: 
      radial-gradient(ellipse at -7px 26px, transparent 50%, red 50%, red calc(50% + 11px), white 0%) 101px -3px/7% 19% no-repeat, 
      radial-gradient(ellipse at 60px 26px, transparent 50%, red 50%, red calc(50% + 11px), white 0%) 454px -4px/7% 19% no-repeat, 
      radial-gradient(ellipse at top, white 20%, red 20%, red calc(21% + 2px), transparent 0%) 50% 0/200% 200% no-repeat,
      linear-gradient(red 50%,transparent 0%) 0 0/100% 10px no-repeat, 
      linear-gradient(to right, gray, blue);
    }
    .header-tr {
      border: 5px solid red;
      margin-top:20px;
      border-top: none;
      height: 100px;
      width: 600px;
      background: 
      radial-gradient(ellipse at -7px 26px, transparent 50%, red 50%, red calc(50% + 11px), white 0%) 101px -3px/7% 19% no-repeat, 
      radial-gradient(ellipse at 60px 26px, transparent 50%, red 50%, red calc(50% + 11px), white 0%) 454px -4px/7% 19% no-repeat, 
      radial-gradient(ellipse at top, white 20%, red 20%, red calc(21% + 2px), transparent 0%) 50% 0/200% 200% no-repeat,
      linear-gradient(red 50%,transparent 0%) 0 0/110px 10px no-repeat,
      linear-gradient(red 50%,transparent 0%) 100% 0/110px 10px no-repeat;
    }

    And if you are open to use multiple element you can rely on pseudo element and some border-radius but you have also to manage a lot of element:

    body {
      background: gray;
    }
    
    .header {
      margin-top: 30px;
      border: 5px solid red;
      border-top: none;
      height: 100px;
      position: relative;
      overflow: auto;
    }
    
    .top {
      position: absolute;
      top: -40px;
      right: 80px;
      left: 80px;
      height: 80px;
      border: 5px solid red;
      border-top: none;
      border-radius: 0 0 50% 50%;
      background: #fff;
    }
    
    .top:before {
      content: "";
      position: absolute;
      top: 23px;
      right: calc(100% - 11px);
      left: -80px;
      border-top: 18px solid #fff;
      border-radius: 0 50% 0 0;
      border-bottom: 0;
      border-left: 0;
      height: 52px;
      z-index: 0;
    }
    
    .top:after {
      content: "";
      position: absolute;
      top: 23px;
      left: calc(100% - 11px);
      right: -80px;
      border-top: 18px solid #fff;
      border-radius: 50% 0 0 0;
      border-bottom: 0;
      border-right: 0;
      height: 52px;
      z-index: 0;
    }
    
    .header:before {
      content: "";
      position: absolute;
      top: 0;
      right: calc(100% - 88px);
      left: 0;
      border-top: 5px solid red;
      border-radius: 0 50% 0 0;
      border-bottom: 0;
      border-left: 0;
      height: 25px;
      z-index: 99;
    }
    
    .header:after {
      content: "";
      position: absolute;
      top: 0;
      left: calc(100% - 88px);
      right: 0;
      border-top: 5px solid red;
      border-radius: 50% 0 0 0;
      border-bottom: 0;
      border-right: 0;
      height: 25px;
      z-index: 99;
    }

    And here is an SVG solution:

    
      
    

提交回复
热议问题