【发布时间】: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。