Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Concentric circles [duplicate]

Tags:

css

geometry

I want to create two concentric circles in CSS. The inner one has a specified width compaired to the outer one, e.g. 50%. Those circles should be responsive, they should scale properly for all screens.

How can I do this? I prefer not to use position:absolute, javascript or jQuery. I think it should be possible.

Thanks!

enter image description here

like image 521
user3103099 Avatar asked Dec 14 '13 21:12

user3103099


2 Answers

Pure CSS:

#container {
   position: relative;
   width: 100%;
   padding-bottom: 100%;
}

#circle {
   position: absolute;
   width: 50%;
   height: 50%;
   background-color: #000000;
   border-radius: 50%;
}

#small-circle{
  margin-top: 25%;
  margin-left: 25%;
  position: absolute;
  width: 50%;
  height: 50%;
  background-color: #e5e5e5;
  border-radius: 50%;
}

And the HTML:

<div id="container">
   <div id="circle">
      <div id="small-circle">
      </div>
   </div>
</div>

See the Demo

like image 107
Itay Gal Avatar answered Sep 25 '22 10:09

Itay Gal


Ah ... svg can help? You can use CSS on it's elements if needed, but I think you can do it strict and simple:

<!DOCTYPE html >
 <html>
   <head>
     <title> Bla! </title>
   </head>
   <body>
        <svg>
            <circle cx="80" cy="80" r="40" fill='red' stroke-width="20" stroke='black'/ >
        </svg>
   </body>
 </html>
like image 29
Guy Dafny Avatar answered Sep 26 '22 10:09

Guy Dafny