I’m working on a timeline from a mysql table, and I wish to get alternate divs (left and right of the vertical line).
I wonder why this code doesn’t work as expected: all the divs are at right of the vertical line.
css
* {
box-sizing: border-box;
}
/* The actual timeline (the vertical ruler) */
.timeline {
position: relative;
max-width: 1200px;
margin: 0 auto;
/*transform: translate(0px, -1950px);*/ /*fa sballare il pop-up*/
}
/* The actual timeline (the vertical ruler) */
.timeline::after {
content: '';
position: absolute;
width: 6px;
background-color: orange;
top: 0;
bottom: 0;
left: 50%;
margin-left: -3px;
}
/* Container around content */
.modaldivcontainer {
padding: 10px 40px;
position: relative;
background-color: inherit;
width: 50%;
}
/* The circles on the timeline */
.modaldivcontainer::after {
content: '';
position: absolute;
width: 25px;
height: 25px;
right: -17px;
background-color: white;
border: 4px solid #FF9F55;
top: 100px;
border-radius: 50%;
z-index: 1;
}
/* Add arrows to the left container (pointing right) */
.modaldivcontainer:nth-child(even)::before {
content: ' ';
height: 0;
position: absolute;
top: 60px;
width: 0;
z-index: 1;
right: -10px;
border: medium solid orange;
border-width: 10px 0 10px 10px;
border-color: transparent transparent transparent orange;
}
/* Add arrows to the right container (pointing left) */
.modaldivcontainer:nth-child(odd)::before {
content: ' ';
height: 0;
position: absolute;
top: 60px;
width: 0;
z-index: 1;
left: -25px;
border: medium solid orange;
border-width: 10px 10px 10px 0;
border-color: transparent orange transparent transparent;
}
/* Fix the circle for containers on the right side */
.right::after, .modaldivcontainer:nth-child(odd)::after {
left: -16px;
}
/* The actual content */
.content {
padding: 20px 30px;
background-color: snow;
position: relative;
border-radius: 6px;
}
.modaldivcontainer:nth-child(odd) {/*right*/
left: 50%;
}
.modaldivcontainer:nth-child(even) {/*left*/
left: 0;
}
/* modal div BEGIN */
.modaltextdiv {
z-index: 5;
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
overflow: auto;
background-color: rgba(0, 0, 0, 0.4);
display: none; /* hide initially*/
justify-content: center;
align-items: center;
}
/* Modal Content/Box */
.modaldiv-content {
background-color: #fefefe;
margin: 10vh auto; /* 15% from the top and centered */
padding: 2%;
border: 3px solid orange;
width: 90%; /* Could be more or less, depending on screen size */
}
@media (min-width: 1366px) {
.modaldiv-content {
width: auto;
height: auto;
min-width: 50vw;
min-height: 20vh;
display: block;
margin: auto;
max-height: calc(100vh - 2rem);
max-width: calc(100% - 2rem);
object-fit: contain;
border-radius: 8px;
box-shadow: gray 5px 5px 5px;
}
}
/* The Close Button */
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
html
<div class="timeline">
<?php
foreach($result as $row)
{
?>
<div class="button modaldivcontainer" data-modal="<?php echo $row["id"]; ?>" style="top:<?php echo "calc($row[data_inizio_y].$row[data_inizio_m]em - 1950em)"; ?>">
<<?php echo $row["level"]; ?>>
<?php echo $row["titolo"]; ?>
</<?php echo $row["level"]; ?>>
<p><?php echo "$row[data_inizio] / $row[data_fine]"; ?></p>
</div>
<div id="<?php echo $row["id"]; ?>" class="modaltextdiv">
<div class="modaldiv-content">
<a class="close">×</a>
<p><?php echo $row["descrizione"]; ?><img src="<?php echo $row["imagelink"]; ?>" onclick="onClick(this)" /></p>
</div>
</div>
<?php
}
?>
</div>
javascript
var modalBtns = [...document.querySelectorAll(".button")];
modalBtns.forEach(function(btn){
btn.onclick = function() {
var modal = btn.getAttribute('data-modal');
document.getElementById(modal).style.display = "grid";
}
});
var closeBtns = [...document.querySelectorAll(".close")];
closeBtns.forEach(function(btn){
btn.onclick = function() {
var modal = btn.closest('.modaltextdiv');
modal.style.display = "none";
}
});
window.onclick = function(event) {
if (event.target.className === "modaltextdiv") {
event.target.style.display = "none";
}
}