Is it possible to draw circle using css only which can work on most of the browsers (IE,Mozilla,Safari) ?
-
6This question has been asked many timesOverZealous– OverZealous2011-08-04 06:21:18 +00:00Commented Aug 4, 2011 at 6:21
-
1This is included in How to make a circle around content using CSS?Martin Thoma– Martin Thoma2013-06-29 17:28:18 +00:00Commented Jun 29, 2013 at 17:28
Add a comment
|
6 Answers
Yep, draw a box and give it a border radius that is half the width of the box:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
Working demo:
#circle {
background: #f00;
width: 200px;
height: 200px;
border-radius: 50%;
}
<div id="circle"></div>
6 Comments
adam
I am using IE8, and this demo does not work. It shows a red square.
jcreamer898
IE8 does not support border-radius, so that makes sense... Great idea for modern browsers though, very cool...
Gavin
Instead of supporting IE8 please ask your clients if you can show a message telling the user to upgrade their browser. It will benefit everyone, and Microsoft recommends it. Google even discontinued IE8 support in their web apps (Gmail, Calendar, Drive, Docs, etc.) at the end of 2012. It's ridiculous to support a 5 year old browser.
fearis
use a polyfille for ie8 css3pie.com and use border-radius:100%; for responsive circle use padding-bottom:40%; width:40%; height:0; overflow:visible;
Atav32
this doesn't work well if the circle is really really small
|
You could use a .before with a content with a unicode symbol for a circle (25CF).
.circle:before {
content: ' \25CF';
font-size: 200px;
}
<span class="circle"></span>
I suggest this as border-radius won't work in IE8 and below (I recognize the fact that the suggestion is a bit mental).
4 Comments
Tatu Ulmanen
:before doesn't work in IE7 and below, so this method only gains support for IE8 but makes it very hard to position the circle correcly. For example, font-size of 200px doesn't equate to a circle with a diameter of 200px and you lose antialiasing on some systems.Pierre de LESPINAY
Maybe also we can set
margin: -0.5em -0.3em -0.3em -0.1embjg222
Given that at this point, IE 8 is nearly 10 years old, this should no longer be the accepted answer. It is reasonable to drop support for it, as according to caniuse.com/usage-table, IE 8 currently has a 0.18% share of usage, and most modern websites have done so. The border-radius property is now supported pretty much across the board (caniuse.com/#search=border-radius), so should be the accepted answer.
oldboy
is there a way to appease the SEO gods, even if i use an image of circular text, instead of rotating each letter?
- Create a div with a set height and width (so, for a circle, use the same height and width), forming a square
- add a
border-radiusof 50% which will make it circular in shape. (note: no prefix has been required for a long time) - You can then play around with
background-color/ gradients / (evenpseudo elements) to create something like this:
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
.yellow {
background-color: yellow;
}
.sphere {
height: 200px;
width: 200px;
border-radius: 50%;
text-align: center;
vertical-align: middle;
font-size: 500%;
position: relative;
box-shadow: inset -10px -10px 100px #000, 10px 10px 20px black, inset 0px 0px 10px black;
display: inline-block;
margin: 5%;
}
.sphere::after {
background-color: rgba(255, 255, 255, 0.3);
content: '';
height: 45%;
width: 12%;
position: absolute;
top: 4%;
left: 15%;
border-radius: 50%;
transform: rotate(40deg);
}
<div class="sphere red"></div>
<div class="sphere green"></div>
<div class="sphere blue"></div>
<div class="sphere yellow"></div>
<div class="sphere"></div>
6 Comments
Atav32
pretty awesome gradients
jbutler483
@Atav32: thanks! It's actually done using multiple box shadows :)
jbutler483
thank you @degenerate ! I hope you well on your CSS journey :)
NickG
I was going to post an angry reply saying that it's the same answer as Tatu's but then I clicked "Run Code".... #micdrop
jbutler483
thanks @NickG I appreciate it :)
|