边界半径,点之间有自定义空格 [英] Border radius with custom spaces between dotted

查看:83
本文介绍了边界半径,点之间有自定义空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在div元素中使用了自定义虚线样式边框.我必须使用背景创建自定义边框,因为必须在点之间定义空格.但是由于边框半径,中没有显示.我该如何解决该问题或其他解决方案?

我希望自定义边框也遵循半径.

 .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> 

解决方案

这可能更适合SVG,您可以使用

检查此问题以获取有关如何使用SVG定义/控制半径的更多方法: SVG圆角

如果要处理一个圆,则另一个相关问题:如何创建等距的虚线圆?

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>

解决方案

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?

这篇关于边界半径,点之间有自定义空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆