【问题标题】:How to make a div with a circular shape? [duplicate]如何制作圆形的div? [复制]
【发布时间】:2014-10-05 02:12:59
【问题描述】:

我想创建一个背景颜色为红色且形状完全为圆形的 div

我该怎么做?

css或jquery都可以用

【问题讨论】:

    标签: css css-shapes


    【解决方案1】:

    使用 50% 的边框半径属性。

    例如:

    .example-div {
    
        border-radius: 50%
    
    }
    

    【讨论】:

      【解决方案2】:

      Demo

      css

      div {
          width: 100px;
          height: 100px;
          border-radius: 50%;
          background: red;
      }
      

      html

      <div></div>
      

      【讨论】:

        【解决方案3】:

        你可以这样做

        FIDDLE

        <div id="circle"></div>
        

        CSS

        #circle {
            width: 100px;
            height: 100px;
            background: red;
            -moz-border-radius: 50px;
            -webkit-border-radius: 50px;
            border-radius: 50px;
        }
        

        其他形状SOURCE

        【讨论】:

        • 使用以像素为单位的border-radius值来做一个圆不是一个好方法..改用border-radius:50%
        【解决方案4】:

        HTML div 元素与 SVG circle 基元不同,总是矩形的。

        您可以使用圆角(即 CSS border-radius)使其看起来是圆的。在方形元素上,50% 的值自然形成一个圆圈。在你的 HTML 中使用这个,甚至是 SVG:

        document.body.innerHTML+='&lt;i&gt;&lt;/i&gt;'.repeat(4);
        i{border-radius:50%;display:inline-block;background:#F48024;}
        svg {fill:#F48024;width:60px;height:60px;}
        i:nth-of-type(1n){width:30px;height:30px;}
        i:nth-of-type(2n){width:60px;height:60px;}
        <svg viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg">
          <circle cx="60" cy="60" r="60"/>
        </svg>

        【讨论】:

          【解决方案5】:
          .circle {
              border-radius: 50%;
              width: 500px;
              height: 500px;
              background: red;
          }
          
          <div class="circle"></div>
          

          看到这个FIDDLE

          【讨论】:

            【解决方案6】:

            通过使用 50% 的边框半径,您可以制作一个圆。 这是一个例子:

            CSS:

            #exampleCircle{
                width: 500px;
                height: 500px;
                background: red;
                border-radius: 50%;
            }
            

            HTML:

            <div id = "exampleCircle"></div>
            

            【讨论】:

              猜你喜欢
              • 2013-08-25
              • 2012-02-04
              • 1970-01-01
              • 1970-01-01
              • 2016-08-13
              • 1970-01-01
              • 2010-12-25
              • 2014-07-17
              • 2021-12-30
              相关资源
              最近更新 更多