Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

css - circle with margin on border

Tags:

css

I am trying to create a circle with an outline that has margin.
Everything seems to work except i cant seem to get that few px of margin in there.
Any suggestions please?

enter image description here

.ui-corner-all { -moz-border-radius: 30px; -webkit-border-radius: 30px; border-radius: 30px; border: 1px solid black; margin:5px; width:30px; height:30px;}

heres my fiddle: http://jsfiddle.net/nalagg/K6pdr/

like image 438
t q Avatar asked Oct 12 '12 19:10

t q


2 Answers

I'd say to treat it like this:

Outer "border" - use a box shadow
Inner "margin" - use a white border
Inner area - use background color

All together you get:

.circle {
  background-color: #F80;
  border: 3px solid #FFF;
  border-radius: 18px;
  box-shadow: 0 0 2px #888;
  height: 30px;
  width: 30px;
}
<div class="circle"></div>

You can make the outer border more distinct by setting blur-radius to 0 on box-shadow.

.circle {
  background-color: #F80;
  border: 3px solid #FFF;
  border-radius: 18px;

  /* offset-x | offset-y | blur-radius | spread-radius | color */
  box-shadow: 0 0 0 2px #888;
  height: 30px;
  width: 30px;
}
<div class="circle"></div>

As an alternative, you could use a second element:

.circle {
  border: 1px solid #CCC;
  border-radius: 19px;
  display: inline-block;
}

.inner {
  background-color: #F80;
  border-radius: 15px;
  margin: 3px;
  height: 30px;
  width: 30px;
}
<div class="circle">
  <div class="inner"></div>
</div>
like image 177
zzzzBov Avatar answered Sep 22 '22 07:09

zzzzBov


As others have said, only firefox supports this. Here is a work around that does the same thing, and even works with dashed outlines.

circle

.has-outline {
    background: #51ab9f;
    border-radius: 50%;
    padding: 5px;
    position: relative;
    width:200px;
    height:200px;
}
.has-outline:after {
  border-radius: 50%;
  padding: 5px;
  border: 2px dashed #9dd5cf;
  position: absolute;
  content: '';
  top: -6px;
  left: -6px;
  bottom: -6px;
  right: -6px;
}
<div class="has-outline">
</div>
like image 39
RobKohr Avatar answered Sep 24 '22 07:09

RobKohr