html - 带虚线边框的 CSS3 六边形

标签 html css svg css-shapes

我可以实现如下所示的具有实心边框的六边形:

.hex {
  margin-top: 70px;
  width: 208px;
  height: 120px;
  background: red;
  position: relative;
}
.hex:before,
.hex:after {
  content: "";
  border-left: 104px solid transparent;
  border-right: 104px solid transparent;
  position: absolute;
}
.hex:before {
  top: -59px;
  border-bottom: 60px solid red;
}
.hex:after {
  bottom: -59px;
  border-top: 60px solid red;
}
.hex.inner {
  background-color: lightgreen;
  -webkit-transform: scale(.98, .98);
  -moz-transform: scale(.98, .98);
  transform: scale(.98, .98);
  z-index: 1;
}
.hex.inner:before {
  border-bottom: 60px solid lightgreen;
}
.hex.inner:after {
  border-top: 60px solid lightgreen;
}
<div class="hex">
  <div class="hex inner">
  </div>
</div>

但是,我想创建一个带虚线边框的六边形,如下图所示:

Hexagon with a dotted border

最佳答案

这是一个带有 inline svg 的方法使用:

svg{width:30%;margin:0 auto;}
<svg viewbox="0 0 100 100" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <polygon fill="#92D050" 
           stroke="red"
           stroke-width="1"
           stroke-linecap="round"
           stroke-dasharray="0.5,3"
           points="50 1 95 25 95 75 50 99 5 75 5 25"/>
</svg>

关于html - 带虚线边框的 CSS3 六边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36477745/

相关文章:

javascript - jQuery//为什么这个 if 语句不正确?

javascript - 删除子元素,但使用 jQuery/javascript 保留内容

html - 如何将 div 中的某物对齐到底部?

javascript - 如何从 HTML 动画渲染 MP4 电影

html - 垂直对齐 svg 内的图像

javascript - 如何使用 Selenium webdriver 测试对 SVG 对象的点击?

javascript - 窗口滚动事件已停止在整个域的所有实现上触发

javascript - 使用 jQuery/CSS 选择属性值

CSS背景图片动画变成空白

html - Vuetify 和布局网格系统 : limiting vertically an element