【发布时间】:2017-05-15 02:17:39
【问题描述】:
我正在尝试使用 flexbox 制作文本滑块。
我希望问题 div 下的所有子元素都像您在 chrome 中看到的那样折叠。
在实际代码中,非活动元素将设置为 translateX(100%),活动索引元素将设置为 0%。
我之所以要使用 flexbox 是 Ques*: 应该与问题文本的第一行对齐,并且 text-container div 应该是中心question div 无论 q-text div 的长度是多少。 (尝试不使用 flex 但我无法对齐 Quest* 和 第一行 文本)
与示例代码一样,由于文本长度不同,它具有不同的中心位置。
在 Chrome 中它工作正常。 但是,它不在 Safari 中(使用最新版本的 Safari)。
如果有更好的方法来实现这一点,我很高兴看到!
#container {
width: 100%;
height: 200px;
background: black;
}
.question {
display: -webkit-flex;
display: flex;
height: 100%;
width: 100%;
overflow: hidden;
justify-content: center;
align-items: center;
-webkit-justify-content: center;
-webkit-align-items: center;
}
.text-container {
display: -webkit-flex;
display: flex;
width: 100%;
position: absolute;
color: white
}
.q {
width: 25%;
display: flex;
justify-content: center;
align-items: center;
-webkit-justify-content: center;
-webkit-align-items: center;
align-self: baseline;
}
.q-text {
width: 75%;
padding-right: 12%;
}
<html>
<body>
<div id="container">
<div class="question">
<div class="text-container">
<div class="q">
Qest1:
</div>
<div class="q-text">
1Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type an
</div>
</div>
<div class="text-container">
<div class="q">
Qest2:
</div>
<div class="q-text">
2Lorem Ipsum is simply dummy text of the printing and ty
</div>
</div>
<div class="text-container">
<div class="q">
Qest3:
</div>
<div class="q-text">
3Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when
</div>
</div>
</div>
</div>
</body>
</html>
【问题讨论】:
-
由于您的文字重叠,即使在 Chrome 中,您能否发布一张显示所需结果的图片?
-
我希望所有的东西都重叠。这样我就可以在加载时将所有不活动的设置为 translateX(100%) 然后使用 js 一个一个地滑动。但在 safari flex center 中不起作用。
标签: javascript html css flexbox