首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >水平堆叠时间线的一致左边距百分比间距

问水平堆叠时间线的一致左边距百分比间距
EN

Stack Overflow用户
提问于 2020-05-05 05:03:17
回答 1查看 66关注 0票数 0

我正在制作一个时间表,其中每个日期或日期范围都有行,并用条形图表示时间跨度。我想我应该得到最早日期和最晚日期之间的天数,然后计算宽度和左边距或每个日期栏的百分比(因此总时间的x%就是宽度,开始日期和最早日期之间的时间除以总时间就是左边距百分比)。

我还想在显示当前日期的所有其他行的顶部显示一个竖条。不过,我最终得到的结果似乎并不管用。

每当我改变屏幕的宽度时,“当前日期”栏与其他栏的相对位置不同。不过,正常的日期栏似乎运行正常。

有没有更好/更一致的方法来实现这一点?

这是一个包含完整html和css的jsfiddle,以及'current date‘行的类:

https://jsfiddle.net/cLxw5atv/

代码语言:javascript
复制
.current-date-bar {
background-color: green; 
height:110%; 
width: 3px; 
margin-left:35%;
position: absolute;
top: 0;
z-index:100;
}
EN

回答 1

Stack Overflow用户

发布于 2020-05-06 01:35:17

我实现了这一点,但我必须将当前日期栏添加到每一行,并使用边距偏移。我不确定是否有更好的方法来实现这一点,但如果有人对我是如何工作的感到好奇,我做了一个更新的小提琴:

https://jsfiddle.net/bnztvkL4/1/

代码语言:javascript
复制
<div class="centered-contents" style="margin-top: 50px;">
<div class="timeline">
<div class="timeline-container">

    <div class="timeline-date">
        <div class="timeline-date-label">
        Date 1
        </div>
        <div class="timeline-date-contents">
            <div class="date-bar timeline-tooltip" style="width: 38%; margin-left:0%;">
                <span class="timeline-tooltiptext">03/30/2020 - 04/30/2020</span>
            </div>
            <div class="current-date-bar"></div>
        </div>
    </div>

    <div class="timeline-date timeline-date-alt">
        <div class="timeline-date-label">
        Date 2
        </div>
        <div class="timeline-date-contents">
            <div class="date-bar timeline-tooltip" style="width: 70%; margin-left:10%;">
                <span class="timeline-tooltiptext">04/12/2020 - 08/19/2020</span>
            </div>
            <div class="current-date-bar"></div>
        </div>
    </div>

    <div class="timeline-date">
        <div class="timeline-date-label">
        Date 3
        </div>
        <div class="timeline-date-contents">
            <div class="date-bar timeline-tooltip" style="width: 30%; margin-left:60%;">
                <span class="timeline-tooltiptext">06/30/2020 - 09/14/2020</span>
            </div>
            <div class="current-date-bar"></div>
        </div>
    </div>

    <div class="timeline-date timeline-date-alt last-date">
        <div class="timeline-date-label">
        Date 4
        </div>
        <div class="timeline-date-contents">
            <div class="date-bar timeline-tooltip" style="width: 10px; margin-left:100%;">
                <span class="timeline-tooltiptext">10/18/2020</span>
            </div>
            <div class="current-date-bar">
                <div class="current-date-bottom"></div>
                <div class="current-date-text">
                    <span>04/25/2020</span>
                </div>
            </div>
        </div>
    </div>

</div>
</div>

​

代码语言:javascript
复制
.centered-contents {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: 20px;
}

.timeline {
    width: 90%;
    color: #7e7e7e;
}

.timeline-container {
    width: 100%;
    border: solid 1px #ccc;
    position: relative;
}

.timeline-date {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    align-items: center;
}

.last-date {
    border-bottom: 0;
}

.timeline-date-label,
.timeline-date-contents {
    padding: 10px;
    display: flex;
    flex-direction: column;
    flex-basis: 100%;
    flex: 1;
}

.timeline-date-contents {
    padding: 10px 10px 0px 0px;
}

.timeline-date-label {
    min-width:100px;
    max-width: 100px;
    word-wrap: break-word;
    border-right: solid 1px #ccc;
    text-align: right;
}

.timeline-current-date {
    margin-left: 100px;
}

.date-bar {
    background-color: #7BAAF7;
    height:20px;
}

.date-bar:hover {
    background-color: #9bb5de;
}


.current-date-bar {
  background-color: green;
  width: 2px;
  z-index: 50;
  height: 40px;
  margin-left: 25%;
  margin-top:-30px;
}

.current-date-text {
  position: absolute;
  margin-left: -35px;
  top: 100%;
  padding-top: 7px;
}

.current-date-bottom {
  position: absolute;
  top: 100%;
  width:2px;
  background-color: green;
  height: 7px;
}

.timeline-date-alt {
    background-color: #e6e6e6;
}

.timeline-tooltip {
  position: relative;
  display: inline-block;
}

.timeline-tooltip .timeline-tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 200;
  top: 150%;
  left: 50%;
  margin-left: -60px;
}

.timeline-tooltip .timeline-tooltiptext::after {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent black transparent;
}

.timeline-tooltip:hover .timeline-tooltiptext {
  visibility: visible;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61601571

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档