Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Circle with border looks not circular, jagged and not smooth, why?

Tags:

html

css

why is my css circle not smooth?

If i do a HTML5 Canvas its really nice.

<div id="circle"></div>
    <style>
    #circle {
    width: 100px;
    height: 100px;
    background: red;
    -moz-border-radius: 50px;
    -webkit-border-radius: 50px;
    border-radius: 50px;
    border:4px solid blue;
}
</style>

http://jsfiddle.net/nkBp8/

Using Chrome and latest IE

Notice the extreme top bottom right left points appear flat.

like image 971
Pinch Avatar asked Jan 30 '14 18:01

Pinch


People also ask

How do you smooth border-radius?

Simply split the colors between different elements — the outer element has the border and the specified border-radius, while the inner element has the background-color and a slightly smaller border-radius.

What is a circle border?

A border that fits a circle within the available space. Typically used with ShapeDecoration to draw a circle. The dimensions assume that the border is being used in a square space.

Which attribute of border makes the border look curved?

Curved border in CSS can be done by border-radius property. Border-radius property removes the corners of the elements and replaces with a certain radius.


2 Answers

Because you think you are using 50% but you aren't, you have used border-radius: 50px; but that's wrong, you are using border of 4px which you forgot to add to the box sizing of your element (If you are aware of how box model of CSS really works).

So you should be using border-radius: 54px; instead cuz your total element's height and width sums up to 108px counting border on both the sides.

Demo


It is better if you use 50% in such cases

Demo

#circle {
    width: 100px;
    height: 100px;
    background: red;
    border-radius: 50%;
    border:4px solid blue;
}

If you want to stick with the 50px measurement, than you can alter the box model rendering by using box-sizing: border-box;

box-sizing: border-box;

Demo (Altered Box Model)

like image 153
Mr. Alien Avatar answered Oct 03 '22 11:10

Mr. Alien


You should use border-radius as a percentage, like this :

    -moz-border-radius: 50%;
    -webkit-border-radius: 50%;
    border-radius: 50%;
like image 37
BenPog Avatar answered Oct 03 '22 11:10

BenPog