skip to Main Content

I am trying to create a very specific image using CSS (unless there is a better way to do it which I have yet to discover). I have created the image using Photoshop, but the resolution is not as high as I want it to be. Below is the code and the result. What I want to do, though, is combine all three of the CSS styles into one so that every time I want to show the image, I don’t have to draw each of the three circles. Any insight would be great, or a better idea to achieve the same thing.

#box {
  display: block;
  width: 1.5em;
  height: 1.5em;
  background-color: #74afad;
  position: absolute;
  border-radius: 100%;
  z-index: -1;
  margin-top: auto;
  margin-bottom: auto;
  vertical-align: middle;
}
#whiteCircle {
  display: block;
  width: 1.25em;
  height: 1.25em;
  background-color: white;
  position: relative;
  border-radius: 100%;
  z-index: 0;
  margin-top: 50%;
  top: -.625em;
  margin-left: 50%;
  left: -.625em;
  vertical-align: middle;
}
#orangeCircle {
  display: block;
  width: 1em;
  height: 1em;
  background-color: #ff7e00;
  position: absolute;
  border-radius: 100%;
  z-index: 1;
  margin-top: 50%;
  margin-left: 50%;
  top: -.5em;
  left: -.5em;
  vertical-align: middle;
}
<div id="box">
  <div id="whiteCircle">
    <div id="orangeCircle">
    </div>
  </div>
</div>

Thank you!

2

Answers


  1. You can reduce everything to a single CSS class by using pseudo-elements instead of explicit div tags.

    Instead of using an id selector, use a class (.box instead of #box) and then you can
    safely reuse the class throughout your pages.

    #box {
      display: block;
      width: 1.5em;
      height: 1.5em;
      background-color: #74afad;
      position: absolute;
      border-radius: 100%;
      z-index: -1;
      margin-top: auto;
      margin-bottom: auto;
      vertical-align: middle;
    }
    #box:before {
      content: '';
      display: block;
      width: 1.25em;
      height: 1.25em;
      background-color: white;
      position: relative;
      border-radius: 100%;
      z-index: 0;
      margin-top: 50%;
      top: -.625em;
      margin-left: 50%;
      left: -.625em;
      vertical-align: middle;
    }
    #box:after {
      content: '';
      display: block;
      width: 1em;
      height: 1em;
      background-color: #ff7e00;
      position: absolute;
      border-radius: 100%;
      z-index: 1;
      margin-top: 50%;
      margin-left: 50%;
      top: -.5em;
      left: -.5em;
      vertical-align: middle;
    }
    <div id="box"></div>
    Login or Signup to reply.
  2. try using gradients

    <style type="text/css">
    
    .circle{
    width: 1.5em;
    height: 1.5em;
    border-radius: 50%;
    background: -moz-radial-gradient(center, ellipse cover, #ff7e00 0%, #ff7e00 45%, #ffffff 45%, #ffffff 58%, #74afad 58%, #74afad 100%); /* FF3.6+ */
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,#ff7e00), color-stop(45%,#ff7e00), color-stop(45%,#ffffff), color-stop(58%,#ffffff), color-stop(58%,#74afad), color-stop(100%,#74afad)); /* Chrome,Safari4+ */
    background: -webkit-radial-gradient(center, ellipse cover, #ff7e00 0%,#ff7e00 45%,#ffffff 45%,#ffffff 58%,#74afad 58%,#74afad 100%); /* Chrome10+,Safari5.1+ */
    background: -o-radial-gradient(center, ellipse cover, #ff7e00 0%,#ff7e00 45%,#ffffff 45%,#ffffff 58%,#74afad 58%,#74afad 100%); /* Opera 12+ */
    background: -ms-radial-gradient(center, ellipse cover, #ff7e00 0%,#ff7e00 45%,#ffffff 45%,#ffffff 58%,#74afad 58%,#74afad 100%); /* IE10+ */
    background: radial-gradient(ellipse at center, #ff7e00 0%,#ff7e00 45%,#ffffff 45%,#ffffff 58%,#74afad 58%,#74afad 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ff7e00', endColorstr='#74afad',GradientType=1 ); /* IE6-9 fallback on horizontal gradient */
    
    }
    
    </style>
    
    
    <div class="circle"></div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search