1

我正在尝试在 HTML 中制作Muller-Lyer 错觉的一个版本(没有图像文件,因为我想让行长度可变)。

这是我到目前为止所拥有的;它有正确的元素,但不能正常工作。最好的方法是什么?

.arrow {
  border: solid black;
  border-width: 0 4px 4px 0;
  display: inline-block;
  padding: 40px;
}

.right {
  transform: rotate(-45deg);
  -webkit-transform: rotate(-45deg);
}

.left {
  transform: rotate(135deg);
  -webkit-transform: rotate(135deg);
}

.line-container {
  display: flex;
  width: 100%;
  margin: 20px auto;
  align-items: center;
}

.line {
  flex-grow: 1;
  height: 2px;
  background: black;
  position: relative;
}

.line.arrow-right:after {
  position: absolute;
  content: '';
  bottom: -10px;
  right: 0;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 10px solid transparent;
}

.line.arrow-left:after {
  position: absolute;
  content: '';
  top: -10px;
  left: 0;
  width: 0;
  height: 0;
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 10px solid transparent;
}

label {
  margin: 0 15px;
}
<i class="arrow right"></i><div class="line-container"><span class="line arrow-left"></span><span class="line arrow-right"></span>
</div><i class="arrow left"></i>
4

1 回答 1

0

我使用了您的基本 cde 并尝试简化一下。看看这个codepen。是你要找的吗?使用旋转边框的“弱点”是箭头比容器 div 长,这就是我添加一些边距的原因。最好的解决方案可能是使用SVG 线条

.line-container {
  margin: 80px;
  width: 400px;
  height: 100px;
  position: relative;
}

.arrow {
  position: absolute;
  border: solid black;
  border-width: 0 8px 8px 0;
  height: 100px;
  width: 100px;
}

.right.out {
   right: 16px;
}

.left.out {
   left: 16px;
}

.right.in {
   left: -120px;
}

.left.in {
   right: -120px;
}

.right {
  transform: rotate(-45deg);
  -webkit-transform: rotate(-45deg);
}

.left {
  transform: rotate(135deg);
  -webkit-transform: rotate(135deg);
}

.line {
  width: 100%;
  border-top: 8px solid black;
  position: absolute;
  top: 50%;
  left: 0;
}
<div class="line-container">
  <i class="arrow right in"></i>
  <div class="line"></div>
  <i class="arrow left in"></i>
</div>    

<div class="line-container">
  <i class="arrow left out"></i>
  <div class="line"></div>
  <i class="arrow right out"></i>
</div>    
  

于 2020-08-26T05:10:47.217 回答