代码之家  ›  专栏  ›  技术社区  ›  ADH - THE TECHIE GUY

使用css可以创建左右两边都是绝对圆的矩形吗?

  •  1
  • ADH - THE TECHIE GUY  · 技术社区  · 8 年前

    在这里,我试图创造的是显示在图像 https://i.stack.imgur.com/qZIEJ.png

    我已经用过 border-radius 但这对我没有帮助。我到目前为止所做的工作在下面的片段中给出:

    .button-holder{
        width:300px;
        height:100px;
    }
    .button{
        width:80%;
        height:65%;
        border-radius:50%;
        border:2px solid #000;
        background-color:#063755;
    }
    <div class="button-holder">
       <div class="button"></div>
    </div>

    请注意:-我知道通过合并可以获得形状 倍数 <div> 标签,但对我没有帮助。我在找答案 只有一个 <DIV & GT; 标签。

    3 回复  |  直到 8 年前
        1
  •  3
  •   fubar    8 年前

    你需要用一半的高度 px 不是 % .

    .button-holder{
        width:300px;
        height:100px;
    }
    .button{
        width:80%;
        height:65%;
        border-radius:32.5px;  // 100px * 0.65 * 0.5 = 32.5px
        border:2px solid #000;
        background-color:#063755;
    }
    <div class="button-holder">
       <div class="button"></div>
    </div>
        2
  •  1
  •   cup_of    8 年前

    你可以使用这样的pSuedoe元素:

    .button-holder {
      width: 300px;
      height: 100px;
      background-color: #063755;
      position: relative;
      margin: 0 auto;
    }
    
    .button-holder:before {
      content: '';
      position: absolute;
      height: 100%;
      width: 33.33%; /* height/width */
      top: 0;
      left: -16.665%; /* 1/2 of the width */
      border-radius: 100%;
      background-color: #063755;
    }
    
    .button-holder:after {
      content: '';
      position: absolute;
      height: 100%;
      width: 33.33%;
      top: 0;
      right: -16.665%;
      border-radius: 100%;
      background-color: #063755;
    }
    <div class="button-holder">
    
    </div>
        3
  •  0
  •   Lakshya Srivastava    8 年前

    试试这个:

    <html>
    
    <head>
      <style>
        #corner {
          border-radius: 100px 100px 100px 100px;
          background: #73AD21;
          padding: 20px;
          width: 400px;
          height: 150px;
        }
      </style>
    </head>
    
    <body>
      <p id="corner"></p>
    </body>
    
    </html>

    output

    推荐文章