I am trying to construct a simple timeline event div in HTML/CSS. It's basically just a colored rectangle with some text inside (a title). The timeline scrolls horizontally.
The thing that I don't seem to be able to figure out is how to keep the title of the event div in view when the timeline is scrolled. I would like the title to move all the way to the right and even outside the container so that it stays visible as long as the container div is in view. Is that possible at all in CSS?
This is what I have so far:
<html>
<style>
.dummy_timeline {
width:5000px;
top:0px;
left:0px;
height:20px;
background: linear-gradient(90deg, #222 1%, transparent 1%) 1px 0, #fff;
background-size: 200px 1px;
}
.container {
overflow: visible;
position:absolute;
background:#eee;
border:1px solid black;
width:200px;
height:50px;}
.title {
position: absolute;
left:0;
}
</style>
<body>
<!-- JUST A TIMELINE PLACEHOLDER SO THAT THE VIEW CAN SCROLL -->
<div class='dummy_timeline'></div>
<!-- EVENT 1 -->
<div class='container' style='left:120px; top:40;'>
<div class='title'>TITLE1</div>
</div>
<!-- EVENT 2 -->
<div class='container' style='left:50px; top:140;'>
<div class='title'>TITLE2</div>
</div>
</body>
</html>
What I need to happen is this:
(1) When the div is completely in view the title stays in its default position
OUTSIDE THE VIEW | IN VIEW
|
| [----------------]
| [ TITLE2 ]
| [----------------]
|
(2) When srolling, the title starts moving to the right to stay visible
OUTSIDE THE VIEW | IN VIEW
|
|---------]
| TITLE2 ]
|---------]
|
(3) When srolling even more, the title moves out of its container and stays in view until the container has completely disappeared
OUTSIDE THE VIEW | IN VIEW
|
|-]
| ]TITLE2
|-]
|
| = the left-most side of the browser window