【发布时间】:2017-10-12 14:08:21
【问题描述】:
我正在尝试制作一个 flexbox 水平时间轴
我有申请 :nth-child(2n) { transform: translateY(100%); } 的想法,但我遇到了很多问题来解决这个问题:
- 时间线之前的内容进入时间线(无法清除它们)
- 向父级添加
overflow-x: auto;也会自动添加overflow-y,如果您隐藏overflow-y,则只有一半时间线可见
还有另一种方法可以让 flexbox 成为可能吗?我也尝试了边距,但项目位置没有很好地居中
@import "compass/css3";
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: flex;
/* This line make an undesired Y scrollbar */
overflow-x: auto;
}
.flex-item {
background: tomato;
width: 200px;
height: 150px;
color: white;
display: flex;
align-self: flex-end;
align-items: flex-end;
justify-content: center;
}
.flex-item:nth-child(2n) {
align-self: flex-end;
align-items: flex-start;
transform: translateY(100%);
}
/* Random heights for testing */
.flex-item:nth-child(5) {
height: 100px;
}
.flex-item:nth-child(3) {
height: 200px;
}
.flex-item:nth-child(4) {
height: 100px;
}
.flex-item:nth-child(6) {
height: 200px;
}
<div>
<p>This text is ok, but there is an undesired Y scrollbar on the timeline</p>
</div>
<ul class="flex-container">
<li class="flex-item"><span>text</span></li>
<li class="flex-item"><span>text</span></li>
<li class="flex-item"><span>text</span></li>
<li class="flex-item"><span>text</span></li>
<li class="flex-item"><span>text</span></li>
<li class="flex-item"><span>text</span></li>
</ul>
<div>
<p>This text should go after the timeline</p>
</div>
【问题讨论】:
-
“时间线进入之前的内容”是什么意思?
-
嗨 rebecca,检查示例代码:codepen.io/anon/pen/aLjEdo 如何使用
transform: translateY(100%);转换时间线的一半@ 我无法检测到底部元素的高度 -
在 SO 上,您应该尝试自己编写代码。在 doing more research 之后,如果您有问题,您可以发布您尝试过的内容,并清楚地解释什么不起作用并提供一个 Minimal, Complete, and Verifiable example.
-
我使用您的函数添加了 sn-p 代码并对其进行了更新以使其更清晰,希望现在更清晰