html - 我怎样才能使 Css Shape 像第一张图片一样

标签 html css css-shapes

enter image description here

enter image description here

我使用 CSS border-left 和 border-right 以及 border-top 属性做了第二个,代码如下。

现在我只想像第一张图片一样制作带边框的形状。

.team-social-icons a {
    background: #3C4E62;
    display: inline-block;
    width: 30px;
    height: 20px;
    color: #fff;
    position: relative;
}

.team-social-icons a:before {
    position: absolute;
    left: 0;
    top: -8px;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-bottom: 8px solid #3C4E62;
    content: "";
}
.team-social-icons a:after {
    position: absolute;
    left: 0;
    bottom: -8px;
    border-left: 15px solid transparent;
    border-right: 15px solid transparent;
    border-top: 8px solid #3C4E62;
    content: "";
}

最佳答案

一个六边形可以由三个矩形构成,每个矩形都有左右边框(但没有上下边框),每个矩形都旋转 60 度。这可以通过一个 :before:after 方便地完成。

要使内容居中,您可以将 flexalign-items/justify-content 一起使用。

.hexagon {
  display: inline-block;
  width: 120px;
  height: 69px;
  border-left: 1px solid black;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 42px;
}
.hexagon:before, .hexagon:after {
  content: '';
  position: absolute;
  left: -1px;
  top: -1px;
  right: -1px;
  bottom: -1px;
  border-left: 1px dashed black;
  border-right: 1px dashed black;
}
.hexagon:before {transform:rotate(60deg);}
.hexagon:after {transform:rotate(-60deg);}
<div class="hexagon"><b>1234</b>happy people</div>

关于html - 我怎样才能使 Css Shape 像第一张图片一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46285580/

相关文章:

javascript - 圆弧进度条

html - 如何用缩放字体大小的圆圈包围数字?

html - 创建对 Angular 线内容框的最有效方法?

javascript - 将 jquery 动画转换为 CSS3

javascript - 使用 Javascript 将图像序列转换为视频

javascript - 在 Bootstrap Carousel Load 之前显示加载微调器

css - 照片库 z-index 问题

html - 插入图片时布局移动几个像素

Javascript onsubmit 与 cgi 操作?

Javascript a4 纸张大小