首页 > 如何用 css 画出一个椭圆?

如何用 css 画出一个椭圆?

.div {
  width: 100px;
  height: 50px;
  border-radius: 25px;
}

不好看。。。


svg也是一个比较好的方案


比较全的,用html5的canvas画的 stackoverflow

<script>
var canvas = document.getElementById('thecanvas');

if(canvas.getContext) 
{
  var ctx = canvas.getContext('2d');
  drawEllipse(ctx, 10, 10, 100, 60);
  drawEllipseByCenter(ctx, 60,40,20,10);
}

function drawEllipseByCenter(ctx, cx, cy, w, h) {
  drawEllipse(ctx, cx - w/2.0, cy - h/2.0, w, h);
}

function drawEllipse(ctx, x, y, w, h) {
  var kappa = .5522848,
      ox = (w / 2) * kappa, // control point offset horizontal
      oy = (h / 2) * kappa, // control point offset vertical
      xe = x + w,           // x-end
      ye = y + h,           // y-end
      xm = x + w / 2,       // x-middle
      ym = y + h / 2;       // y-middle

  ctx.beginPath();
  ctx.moveTo(x, ym);
  ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
  ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
  ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
  ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
  //ctx.closePath(); // not used correctly, see comments (use to close off open path)
  ctx.stroke();
}

</script>

http://css-tricks.com/the-shapes-of-css/

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

1楼的答案.......


http://jsfiddle.net/81nr1902/


我之前给公司做的一个网站有类似的代码,截图是这样子的:

我把它整理了一下,代码如下:
css画椭圆

<div class="container introduce">
    <div class="introduce_zi">
      <div class="introduce_sun"></div> 
    </div>
</div><!--introduce-->

  /*introduce*/
.introduce{max-width:700px; height:260px; background-color:#62a97b; border-radius:50%; overflow:hidden; position:relative; z-index:2;}
.introduce .introduce_zi{max-width:640px; height:200px; background-color:#26699e; border-radius:50%; margin:0 auto; position:relative; top:-25px;}
.introduce .introduce_zi .introduce_sun{max-width:460px; height:140px; background-color:#593568; border-radius:50%; margin:0 auto; position:relative; top:-25px;}
【热门文章】
【热门文章】