Постоянный интервал левого поля в процентах для горизонтальной, сложенной шкалы времени - PullRequest
0 голосов
/ 05 мая 2020

Я делаю временную шкалу, в которой есть строки для каждой даты или диапазона дат с полосами для представления временных интервалов. Я решил, что получу количество дней между самой ранней и последней датами, а затем вычислю ширину и левое поле или каждую полосу даты в процентах (так что x% от общего времени будет шириной, а время между дата начала и самая ранняя дата, разделенная на общее время, будет процентным левым полем).

Я также хотел иметь вертикальную полосу, которая идет поверх всех других строк, показывающих текущую дату. Однако то, что у меня получилось, похоже, не работает.

Каждый раз, когда я меняю ширину экрана, полоса «текущей даты» не остается в том же относительном положении, что и другие полоски. Однако нормальные панели даты, похоже, работают правильно.

Есть ли лучший / более последовательный способ сделать это?

Вот jsfiddle с полными html и css вместе с классом для строки «текущая дата»:

https://jsfiddle.net/cLxw5atv/

.current-date-bar {
background-color: green; 
height:110%; 
width: 3px; 
margin-left:35%;
position: absolute;
top: 0;
z-index:100;
}

1 Ответ

0 голосов
/ 05 мая 2020

Я получил эту работу, но мне пришлось добавить текущую полосу даты в каждую из строк и использовать смещение поля. Я не уверен, есть ли лучший способ сделать это, но если кому-то интересно, как у меня это работает, я сделал обновленную скрипку:

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

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

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