I'm developing a control aiming to display activity blocks on a calendar grid. It is a plain JavaScript/CSS, relying on jQuery for DOM manipulation and such. Here is a picture:
There are bands A and B, each containing a couple of activity blocks ([1,2], [3,4]). Activities can either overlap or follow each other sequentially. My goal is to place the activity blocks accordingly: if activities overlap like [1,2], I want them wrap and sit on top of one another like pictured; if they are sequential like [3,4], I want them side by side, NOT like pictured.
Additionally, I would like bands' (A,B) height to adjust automatically. Thus, a band with overlapped activity blocks would have twice the height of the band with sequential ones.
At this point I can get either one or the other.
If activity blocks have display: block;
, the activities wrap regardless whether they actually overlap (3,4). Band's height does get adjusted accordingly.
If activity blocks have display: inline-block;
, activities share the same height so one gets hidden by the other (1,2). The band stays one activity block in height.
Everything is a div
and here is the relevant HTML/CSS:
<div class="band">
<div class="activity-block" style="left: 331.429px; width: 11.4286px;"></div>
<div class="activity-block" style="left: 160px; width: 297.143px;"></div>
</div>
<div class="band">
<div class="activity-block" style="left: 205.714px; width: 22.8571px;"></div>
<div class="activity-block" style="left: 365.714px; width: 3417.14px;"></div>
</div>
<div class="band"></div>
Bands (A, B):
.band {
min-height: 20px;
}
Activity blocks (1,2,3,4):
.activity-block {
background-color: #66C6C2;
border-radius: 3px;
display: block;
height: 20px;
margin-bottom: 5px;
margin-top: 5px;
position: relative;
}
left
and width
of an activity block are set from JavaScript.
I would like to get there using only two CSS classes, one for the band and one for the activity blocks. I realize the goal can be achieved using JavaScript, but I wonder if this is something possible via CSS only.