CSS 在盒子的每一边放上箭头(div)

CSS Put arrows on each side of a Box(div)

需要有关如何在盒子的每一侧都指向外的箭头的帮助。

我有盒子和基本的 CSS 我在另一个堆栈问题上看到的箭头。

需要帮助在那个盒子里制作四个箭头

我是 java 开发人员,所以这不是我的菜

盒子:

#myBox {
  width: 150px;
  height: 150px;
  background-color: grey;
  border: 1px solid black;
}
/*Chevron*/
.Chevron {
  position: relative;
  display: block;
  height: 50px;
  /*height should be double border*/
}
.Chevron:before,
.Chevron:after {
  position: absolute;
  display: block;
  content: "";
  border: 25px solid transparent;
  /*adjust size*/
}
/*Change four 'top' values below to rotate (top/right/bottom/left)*/

.Chevron:before {
  top: 0;
  border-top-color: #b00;
  /*Chevron Color*/
}
.Chevron:after {
  top: -50px;
  /*adjust thickness*/
  border-top-color: #fff;
  /*Match background colour*/
}
<div id="myBox"></div>





<i class="Chevron"></i>

使用Csstriangle。你需要这样的东西吗?

对于每一边,使用下面的代码制作一个三角形:

width: 0;
height: 0;
border-style: solid;
border-width: 100px 100px 100px 0;
border-color: transparent #007bff transparent transparent;

这里是working demo.

由于您希望与这些形状进行交互,因此您最好采用不同的方法来制作三角形,而不是边框​​黑客。

.box {
  height: 150px;
  width: 150px;
  background: lightgray;
  position: relative;
}
.wrap {
  position: absolute;
  top: 0;
  left: 25%;
  height: 25%;
  width: 50%;
  overflow: hidden;
}
.touch {
  position: absolute;
  top: 0;
  left: 50%;
  height: 200%;
  width: 200%;
  transform: rotate(45deg);
  transform-origin: top left;
  background: gray;
  cursor: pointer;
}
.wrap:nth-child(2) {
  transform: rotate(90deg);
  transform-origin: top left;
  top: 25%;
  left: 100%;
}
.wrap:nth-child(3) {
  transform: rotate(180deg);
  transform-origin: top left;
  top: 100%;
  left: 75%;
}
.wrap:nth-child(4) {
  transform: rotate(-90deg);
  transform-origin: top left;
  top: 75%;
  left: 0;
}
.touch:hover {
  background: tomato;
}
<div class="box">
  <span class="wrap"><span class="touch"></span></span>
  <span class="wrap"><span class="touch"></span></span>
  <span class="wrap"><span class="touch"></span></span>
  <span class="wrap"><span class="touch"></span></span>

</div>

我已经使用 nth-child 来正确定位箭头。我还需要使用包装器 div like in this answer 因为 border-hack 在命中测试中不起作用。

我已经使用 CSS 变换和定位对 3 个元素进行了处理。这就是您想要实现的目标吗?

.container {
  width: 100px;
  height: 100px;
  background: grey;
  position: relative;
}

.container .triangles {
  width: 70px;
  height: 70px;
  background: yellow;
  transform: rotate(45deg);
  position: absolute;
  top: 15px;
  left: 15px;
}

.container .triangles .box {
  width: 50px; 
  height: 50px;
  background: blue;
  transform: rotate(-45deg);
  position: absolute;
  top: 10px;
  left: 10px;
  color: white;
}
<div class="container">
  <div class="triangles">
    <div class="box">
      text
    </div>
  </div>
</div>