I am using custom dotted style border in my div element. I have to create custom border using background because I must define spaces between dotted. But in the corners it's not displaying due to the border radius. How can I fix that or any other solution?
I want the custom border to also follow the radius.
.element {
width: 400px;
height: 400px;
background: linear-gradient(to right, black 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(black 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(to right, black 50%, rgba(255, 255, 255, 0) 0%), linear-gradient(black 50%, rgba(255, 255, 255, 0) 0%);
background-position: top, right, bottom, left;
background-repeat: repeat-x, repeat-y;
background-size: 20px 1px, 1px 20px;
border-radius: 70px;
}
<div class="element">
</div>
you can just adjust the size with the background-size property, the proportion with the background-image property, and the proportion with the linear-gradient percentages. So, you can have several dotted borders using multiple backgrounds. In this example, we have a dotted line of 3px dots and 7px spacing.
IF you're only targeting modern browsers, AND you can have your border on a separate element from your content, then you can use the CSS scale transform to get a larger dot or dash: border: 1px dashed black; border-radius: 10px; -webkit-transform: scale(8); transform: scale(8);
We can create the dashed border by using a path or a polygon element and setting the stroke-dasharray property. The property takes two parameters where one defines the size of the dash and the other determines the space between them.
This is probably more suitable for SVG where you can easily control the border using stroke-dasharray
svg {
width: 250px;
}
path {
fill: none;
stroke-dasharray: 13, 20;
}
path.more {
fill: none;
stroke-dasharray: 10, 30;
}
path.less {
fill: none;
stroke-dasharray: 25, 15;
}
<svg viewBox="50 70 300 300">
<path d="M100,100 h200 a80,80 0 0 1 20,20 v200 a80,80 0 0 1 -20,20 h-200 a80,80 0 0 1 -20,-20 v-200 a80,80 0 0 1 20,-20 z" stroke="black" stroke-width="2" />
</svg>
<svg viewBox="50 70 300 300">
<path d="M100,100 h200 a80,80 0 0 1 20,20 v200 a80,80 0 0 1 -20,20 h-200 a80,80 0 0 1 -20,-20 v-200 a80,80 0 0 1 20,-20 z" class="more" stroke="black" stroke-width="2" />
</svg>
<svg viewBox="50 70 300 300">
<path d="M100,100 h200 a80,80 0 0 1 20,20 v200 a80,80 0 0 1 -20,20 h-200 a80,80 0 0 1 -20,-20 v-200 a80,80 0 0 1 20,-20 z" class="less" stroke="black" stroke-width="2" />
</svg>
Check this question for more ways about how to define/control the radius using SVG: SVG rounded corner
Another related question if you want to deal with a circle: How to create dashed circles with uniform spacing?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With