Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - double/offset border with outer border dashed

Tags:

css

border

I'd like to produce a circle with the outer dashed border offset from the main circle. I've attached a pic for reference.

I have tried using box shadow to achieve this but no luck so far. Is there a way to do this?

enter image description here

like image 253
Ben Avatar asked Sep 02 '25 02:09

Ben


1 Answers

I was able to get this effect by utilizing the pseudo-element selector ::before. (::after would work just as well)

Here is a DEMO

Given the element:

<div class="circle"></div>

Apply the following CSS rule:

.circle {
    position: relative;
    float: left;
    border: 2px dotted black; /* This is the outer border (dotted) */
    background-color: white; /* This is the color of the inner border */
    padding: 10px; /* This is the size of the inner border */
    border-radius: 50%;
}

.circle::before {
    position: absolute;
    display: block;
    content: ' ';
    background-color: #6abde7; /* This is the color of the inner circle */
    width: 150px; /* This controls how wide the circle will be. Remember to subtract padding + border */
    height: 150px; /* This controls how tall the circle will be. Remember to subtract padding + border */
    border-radius: 50%;
}

You can adjust a few of the rules above. They are mainly there just to give shape to the circle for the demo. I've commented the ones that control the styles of the circle.

Explanation

You're basically adding an element inside of the container element via CSS. This won't work on elements that don't support content. (i. e. <input>)

like image 167
crush Avatar answered Sep 07 '25 06:09

crush