William Larsen Bang William Larsen Bang - 1 year ago 148
CSS Question

centered HTML timeline structure using CSS? With only the sides scaling?

Okay so I have this structure that I am trying to create with CSS, but all my attempts have not yielded a proper result, I tried searching the internet for help, and found some guides to timeline structures but none of them seemed to do what I am trying to do.

So here is what my basic structure is: enter image description here

So the idea here is that the window resolution is 1800px in width, and structure is some div container, the light grey background, that is somehow centered either a margin: 0 auto or something else with a set with of 1200px. Then to act as the backbone of the page is the middle red timeline which is centered and will keep the same set width, not a percentage. Around the timeline on the left and right side there will be these tooltip type boxes which will scale in height depending on the amount of text.

Next if you resize the window resolution to something like 1000px in width, therefore smaller than the light grey area. The middle timeline stays the same set width, but the tooltip boxes changes in width and increases in height because of the lack horizontal space, instead it uses the vertical space.
the tooltip boxes will keep the same distance from the timeline, let's say of 15px, so they sort of have to decrease in width from both sides, and that is where I am running into a wall.
enter image description here

The way I imagened it myself was somehow for the timeline to be build out of modules, like shown below, so the tooltips would correspond to a part of the timeline, and then timelines with tooltips would be stacked up on each other. But any solution is appreciated,

enter image description here

Here is a link to what I have so far:


where I am trying to achieve the tooltip scaling, it's not close to perfect, and the timeline height doesn't even adjust with the tooltip height :(

Any suggestions?

Answer Source

In the absence of the rest of the code, I used some of mine. To explain it briefly, I have centered the "timeline" darkred bar and gave it a 2% width, then positioned the other ones accordingly, having a width of 49% - 1% - 20px where the 20px is the distance to the bar.

The right side has a margin-left of 2% (the width of the bar) + double the distance to the bar (we don't want do disregard the left one's margin) This is how the calculations look for the right side:

    .level .right {
        width: calc(49% - 1% - 20px);
        margin-left: calc(2% + 40px);

The full codepen can be viewed here. I hope it hepls!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download