【问题标题】:Semi-oval with CSS带 CSS 的半椭圆形
【发布时间】:2016-12-21 21:32:43
【问题描述】:

我正在尝试在椭圆形和半圆形之间创建混合。

半圆可以在 CSS 中这样创建:

.halfCircle{
     height:45px;
     width:90px;
     border-radius: 90px 90px 0 0;
     -moz-border-radius: 90px 90px 0 0;
     -webkit-border-radius: 90px 90px 0 0;
     background:green;
}

椭圆可以这样制作:

.oval { 
    background-color: #80C5A0;
    width: 400px;
    height: 200px;
    margin: 100px auto 0px;
    border-radius: 200px / 100px;
}

但是如何制作半椭圆形呢?到目前为止,这是我的尝试。发生的问题是我有平顶,找到here。谢谢!

【问题讨论】:

标签: html css css-shapes


【解决方案1】:

我已经用一种可能的解决方案更新了您的演示:

div {
  background-color: #80C5A0;
  width: 400px;
  height: 100px;
  border-radius: 50% / 100%;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}
<div></div>

通过为border-radius 使用基于百分比的单位,无论您的widthheight 值如何,它都应该始终保持平滑的半椭圆。

进行一些小的改动后,您可以将半椭圆垂直分成两半:

div {
  background-color: #80C5A0;
  width: 400px;
  height: 100px;
  border-radius: 100% / 50%;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
<div></div>

【讨论】:

  • 之所以选择,是因为您已经给出了一半椭圆形的两种方法,但是您和 HerrSerker 的两个答案都解决了我的问题 - 谢谢!
【解决方案2】:

http://jsfiddle.net/QGtzW/4/

.halfOval { 
    background-color: #a0C580;
    width: 400px;
    height: 100px;
    margin: 100px auto 0px;

    /* top-right top-left bottom-left bottom-right */
    /* or from 10.30 clockwise */
    border-radius: 50% 50% 0 0/ 100% 100% 0 0;
}

【讨论】:

    【解决方案3】:

    我们也可以使用 css3 radial-gradient() 来绘制这个形状:

    .halfOval {
      background: radial-gradient(ellipse at 50% 100%, #a0C580 70%, transparent 70%);
    }
    

    .halfOval {
      background: radial-gradient(ellipse at 50% 100%, #a0C580 70%, transparent 70%);
      margin: 50px auto;
      height: 100px;
      width: 400px;
    }
    <div class="halfOval"></div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-07
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      相关资源
      最近更新 更多