Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make one circle inside of another using CSS

Tags:

css

I am trying to make one circle inside of another circle using css, but I am having an issue making it completely centered. I am close, but still not there. Any ideas?

<div id="content">
    <h1>Test Circle</h1>
    <div id="outer-circle">
        <div id="inner-circle">
            <span id="inside-content"></span>
        </div>
    </div>
</div>

Here is my CSS:

#outer-circle {
    background: #385a94;
    border-radius: 50%;
    height:500px;
    width:500px;
}
#inner-circle {
    position: relative;
    background: #a9aaab;
    border-radius: 50%;
    height:300px;
    width:300px;
    margin: 0px 0px 0px 100px;
}

Also, here is a fiddle: http://jsfiddle.net/972SF/

like image 591
scapegoat17 Avatar asked Mar 14 '14 13:03

scapegoat17


People also ask

How do I make a circle inside a circle in CSS?

If you want to use only one div to add circle inside circle, then use box-shadow.

How do you make a circle hollow in CSS?

Creating an empty circle with CSS To create an empty circle first of all add an empty <div> element. Use CSS border-radius: 50% to make the div element circular. Additionally set the height, width and border of <div> element.


1 Answers

Ta da!

Explained in the CSS comments:

 #outer-circle {
   background: #385a94;
   border-radius: 50%;
   height: 500px;
   width: 500px;
   position: relative;
   /* 
    Child elements with absolute positioning will be 
    positioned relative to this div 
   */
 }
 #inner-circle {
   position: absolute;
   background: #a9aaab;
   border-radius: 50%;
   height: 300px;
   width: 300px;
   /*
    Put top edge and left edge in the center
   */
   top: 50%;
   left: 50%;
   margin: -150px 0px 0px -150px;
   /* 
    Offset the position correctly with
    minus half of the width and minus half of the height 
   */
 }
<div id="outer-circle">
  <div id="inner-circle">

  </div>
</div>
like image 152
misterManSam Avatar answered Sep 26 '22 19:09

misterManSam