15

我正在尝试创建一个带有边距轮廓的圆圈。
一切似乎都有效,除了我似乎无法获得那么少px的利润。
请问有什么建议吗?

在此处输入图像描述

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

这是我的小提琴:http: //jsfiddle.net/nalagg/K6pdr/

4

4 回答 4

52

我会说这样对待它:

外部“边框” - 使用盒子阴影
内部“边缘” - 使用白色边框
内部区域 - 使用背景颜色

总之,你得到:

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


您可以通过在 box-shadow 上将 blur-radius 设置为 0 来使外边界更加清晰。

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


作为替代方案,您可以使用第二个元素:

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

于 2012-10-12T19:12:52.170 回答
2

正如其他人所说,只有Firefox支持这一点。这是一个解决方法,它做同样的事情,甚至可以使用虚线轮廓。

圆圈

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

于 2020-03-25T12:44:13.613 回答
1

尝试:

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

或使用内部填充:

.ui-corner-all2 { -moz-border-radius: 30px; -webkit-border-radius: 30px; border-radius: 30px; border: 1px solid black; padding: 2px; background: #fcc;  width: 30px; height: 30px; }

另请参阅this fiddle使用margin vs padding CSS属性时的区别。

http://jsfiddle.net/MQx7r/4/

于 2012-10-12T19:09:24.763 回答
0

您可以outline与 结合使用outline-radius。检查这个jsFiddle

于 2012-10-12T19:10:39.823 回答