【问题标题】:How to create a div with pointy edges?如何创建一个带有尖边的 div?
【发布时间】:2019-07-25 21:04:06
【问题描述】:

你能帮我做这样的div吗:

我的代码:

body{
        display: flex;
        justify-content: center;
      }
      #talkbubble {
      width: 160px;
      height: 80px;
      background: #bc0a14;
      position: relative;
      -moz-border-radius: 10px;
      -webkit-border-radius: 10px;
      border-radius: 10px;
    }
    #talkbubble:before {
      content: "";
      position: absolute;
      right: 100%;
      top: 26px;
      width: 0;
      height: 0;
      border-top: 13px solid transparent;
      border-right: 26px solid #bc0a14;
      border-bottom: 13px solid transparent;
    }
    #talkbubble:after {
      content: "";
      position: absolute;
      left: 100%;
      top: 26px;
      width: 0;
      height: 0;
      border-top: 13px solid transparent;
      border-left: 26px solid #bc0a14;
      border-bottom: 13px solid transparent;
    }
<div id="talkbubble"></div>

我想在图片中创建这个样式相同的div

【问题讨论】:

    标签: html css css-shapes


    【解决方案1】:

    这是一个带有伪元素和径向渐变的想法。我使用 CSS 变量轻松调整形状,但这不是强制性的

    .box {
      width: 100px;
      height: 50px;
      margin:0 var(--w,20px);
      display:inline-block;
      border-radius: 15px;
      background: var(--c,red);
      position: relative;
    }
    
    .box:before,
    .box:after {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      width: var(--w,20px);
      right:calc(100% - 2px);
      background:
       radial-gradient(107% 100% at top    left,transparent 96%,var(--c,red) 100%) top, 
       radial-gradient(107% 100% at bottom left,transparent 96%,var(--c,red) 100%) bottom;
      background-size:100% 50.1%;
      background-repeat:no-repeat;
    }
    .box:after {
      left:calc(100% - 2px);
      right:auto;
      transform:scaleX(-1);
    }
    <div class="box"></div>
    
    <div class="box" style="--c:blue;--w:30px;"></div>
    
    <div class="box" style="--c:purple;--w:10px;height:60px"></div>

    【讨论】:

      【解决方案2】:

      请试试这个代码:

      body{
              display: flex;
              justify-content: center;
            }
            #talkbubble {
               width: 180px;
          height: 54px;
          background: #bc0a14;
          position: relative;
          -moz-border-radius: 20px;
          -webkit-border-radius: 20px;
          border-radius: 24px;
          }
          #talkbubble:before {
                content: "";
          position: absolute;
          right: 99%;
          top: 17px;
          width: 0px;
          height: 1px;
          border-top: 9px solid transparent;
          border-right: 10px solid #bc0a14;
          border-bottom: 9px solid transparent;
          }
          #talkbubble:after {
            content: "";
          position: absolute;
          left: 99%;
          top: 17px;
          width: 0;
          height: 1px;
          border-top: 9px solid transparent;
          border-left: 10px solid #bc0a14;
          border-bottom: 9px solid transparent;
          }
      &lt;div id="talkbubble"&gt;&lt;/div&gt;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-17
        • 1970-01-01
        • 2014-05-05
        • 2019-09-09
        • 2014-07-02
        • 2013-04-19
        相关资源
        最近更新 更多