【问题标题】:How to make circle thing in CSS? [duplicate]如何在 CSS 中制作圆形的东西? [复制]
【发布时间】:2016-08-13 18:46:20
【问题描述】:

我需要在灰色条纹上制作白色的东西。我很困惑,因为我以前没有做过这样的事情。你会采用哪种方法来创建这样的东西?

JSFiddle

<div class="stripe"></div>

.stripe {
  background-color: #B7B7B7;
  height: 13vh;
}

提前谢谢你!

【问题讨论】:

标签: html css css-shapes


【解决方案1】:

W3Schools on border-radius property

.stripe {
    background-color: #B7B7B7;
    height: 13vh;
}
.thatwhitethingovergreystripe {
    background-color: white;
    height: 13vh; /* or 100% */
    width: 80px; /* or 6.5vh for semicircle or 13vh for rectangle with r width and semicircle */
    border-top-right-radius: 6.5vh; /* this does the trick; make it any number you like or just make it full height of your div */
    border-bottom-right-radius: 6.5vh; /* and this */
}
<div class="stripe">
    <div class="thatwhitethingovergreystripe"></div>
</div>

【讨论】:

  • 虽然这是一个很好的解决方案,但高度和宽度是不同的值类型,因此它不会在不同的视口高度保持纵横比。此外,为什么不只用一条线来处理边界半径呢?边界半径:0 50% 50% 0;请参阅下面的答案。
【解决方案2】:

我希望您会发现这个答案既简单又完美。

.stripe {
    background-color: #B7B7B7;
    height: 13vh;
}
.whiteThing {
    background-color: white;
    height: 13vh;
    width: 13vh;
    border-radius:0 50% 50% 0;
}
<div class="stripe">
    <div class="whiteThing"></div>
</div>

【讨论】:

    【解决方案3】:

    单个标签 + 伪也可以:

    h1 {
      overflow:hidden;/* to hold shadow of pseudo */
      padding-left:1.5em; /* leave room for the shape */
      line-height:2em;
      }
    h1:before { /* the shape */
      content:'';
      float:left;/* or inline-block or absolute position, works too in flex context*/
      height:2em;/* here height of tag if one line */
      width:2em;/* from a square you can draw a circle */
      margin-left:-2.5em;/* hide half of it or  any amount */
      border-radius:50%;/* draw that circle */
      box-shadow:0 0 500px 500px gray, 0 0  1000px 1000px yellow;;/* paint a hudge shadow to use as background for parent tag */
      }
      /* add borders ? */
    h1 + h1 {
      border:solid;
      border-left:none;
      border-radius: 0 1em 1em  0;
      }
    h1 + h1:before {
     box-shadow:0 0 0 3px,0 0 500px 500px gray, 0 0  1000px 1000px yellow;;/* paint a hudge shadow to use as background for parent tag */
      }
    
    body {
      background:url(http://lorempixel.com/600/400/nature/2);
      }
    <h1> reverse rounded </h1>
    <h1> reverse rounded borders </h1>

    更多示例和不同形状或使用 -http://codepen.io/gcyrillus/pen/yJfjl -http://codepen.io/gcyrillus/pen/Kpvuf -http://codepen.io/gcyrillus/pen/HEFtk -http://dabblet.com/gist/5690173 -http://dabblet.com/gist/5309926

    【讨论】:

      【解决方案4】:

      我就是这样做的

      .s2{
        background-color:white;
        float:left;
        width: 70px;
        height: 13vh;
        border-top-right-radius: 50%;
        border-bottom-right-radius: 50%;
      }
      .stripe {
        background-color: #B7B7B7;
        height: 13vh;
      }
      &lt;div class="s2"&gt;&lt;/div&gt;&lt;div class="stripe"&gt;&lt;/div&gt;

      【讨论】:

      • 哦! ...他们已经回答了:(
      • 不要沮丧。感谢您的回答
      • 谢谢,感谢您也注意到我的回答。 :)
      【解决方案5】:
      <div class="stripe"><span class="circle"></span></div>
      
      .circle {
        border-radius:50%; //makes the square into circle regardless of size
        background: white;
        height:13vh;
        width:13vh;
        display:block;
        overflow:hidden;
       }
      

      【讨论】:

        【解决方案6】:

        你可以这样做,见小提琴:https://jsfiddle.net/5wwg1q5j/3/

        html

        <div class="stripe">
        <div class="rec">
        </div>
        <div class="circle">
        </div>
        </div>
        

        css

        body{margin: 0;}
        .stripe {
          background-color: #B7B7B7;
          height: 100px;
        }
        .rec{
          width: 100px;
          height: 100px;
          background-color: white;
        }
        .circle {
            border-radius: 50%;
            width: 100px;
            height: 100px;
          background-color: white;
          position: absolute;
          left: 50px;
          top: 0;
            /* width and height can be anything, as long as they're equal */
        }
        

        【讨论】:

          【解决方案7】:

          您可能想要使用border-radius 属性。

          HTML:

          <div class="stripe">
          <div class="circle">
          </div>
          </div>
          

          CSS:

              .stripe {
            background-color: #B7B7B7;
            height: 13vh;
          }
          
          .circle{
            background:white;
            width:10%;
            height:100%;
            border-radius:00px 50px 50px 0px;
          }
          

          https://jsfiddle.net/4uk5eyuq/

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2021-08-31
            • 2013-08-25
            • 2014-10-05
            • 2017-01-17
            • 1970-01-01
            • 1970-01-01
            • 2019-04-16
            • 1970-01-01
            相关资源
            最近更新 更多