【问题标题】:Muller Lyer in Html穆勒莱尔在 Html
【发布时间】:2020-08-26 01:28:33
【问题描述】:

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

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

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

【问题讨论】:

  • 最简单的解决方案是使用图片并将其包装到具有值的 div 容器中:object-fit: fill; 然后您提高或降低 div 宽度,图像将水平拉伸或折叠。最简单的解决方案,无需太多编码或使用伪元素,但长度仍然可变。但是,如果您想以复杂的方式进行操作,只需使用 SVG。

标签: html css jspsych


【解决方案1】:

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

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

【讨论】:

  • 这看起来很棒,非常感谢@Yanou!我遇到了一些小问题,箭头与主水平线略有脱节。你有什么建议可以像这个例子(跨浏览器)一样保持它们完全准确吗?
  • 我的技巧是使用position: relative / position: absolute 将线和箭头连接到线容器。这应该可以防止他们彼此远离。
猜你喜欢
  • 1970-01-01
  • 2016-04-25
  • 2014-08-14
  • 1970-01-01
  • 1970-01-01
  • 2018-04-18
  • 1970-01-01
  • 2012-04-30
  • 1970-01-01
相关资源
最近更新 更多