Я рекомендую использовать SCSS
или LESS
в сложных случаях, подобных этому, для более удобного чтения вашего CSS.Я написал этот CSS с использованием SCSS (https://jsfiddle.net/e61oqsdz/), а затем скомпилировал его на каком-то онлайн-сайте в CSS.
Версия SCSS с объяснением:
$li-height: 50px; // set li height here
$marginRight: 5%; // set margin right - the same unit must be used on $li-width so the width
// will be $marginRight smaller(if using % so 100% can be achieved).
$li-width: 20% - $marginRight;
.i_timeliner{
width: 100%;
position:relative;
display: inline-block;
ul{
width: inherit;
margin:0;
padding:0;
list-style:none;
height: auto;
font-size:0; // remove the invisible spaces between the `li` elements
li{
position: relative;
display: inline-block;
vertical-align:top;
box-shadow: 0px 0px 1px 2px #000 inset; // add shadow instead of border
// borders will stack with your width, and even when your elements have
// a total of 100% will get pushed on the next row
// if you have border on any one of them
width: $li-width;
height: $li-height;
margin-right: $marginRight;
.i_timeliner_box{
position: absolute;
left:0;
top:0;
width: 100%;
height: 100%;
font-size: 0.8rem;
*{margin:0;}
}
&:nth-child(2n){ // here i'm pushing the even numbers from top
margin-top: $li-height * 1.5; // 1.5 ratio means 'one height + half-of-height'
// so we can have the vertical space between blocks
}
&:last-child{
// this is your delimiter, it's an empty li, with overwritten properties
position: absolute;
left:0;
top: $li-height * 1.25; // 1.25 - is the ratio for position to middle. Since we
// already have a ratio of 1.5 for even elements, the 0.5 is the space gap, splitting
// in half the space gap is 0.25, right where our delimiter should be,
// adding a $li-height to it, we get 1.25
background: red;
box-shadow: none;
border:0;
height: 2px;
width: 100%;
margin: 0;
font-size:0;
}
}
}
}
.i_timeliner {
width: 100%;
position: relative;
display: inline-block;
}
.i_timeliner ul {
width: inherit;
margin: 0;
padding: 0;
list-style: none;
height: auto;
font-size: 0;
}
.i_timeliner ul li {
position: relative;
display: inline-block;
vertical-align: top;
box-shadow: 0px 0px 1px 2px #000 inset;
width: 15%;
height: 50px;
margin-right: 5%;
}
.i_timeliner ul li .i_timeliner_box {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
font-size: 0.8rem;
}
.i_timeliner ul li .i_timeliner_box * {
margin: 0;
}
.i_timeliner ul li:nth-child(2n) {
margin-top: 75px;
}
.i_timeliner ul li:last-child {
position: absolute;
left: 0;
top: 62.5px;
background: red;
box-shadow: none;
border: 0;
height: 2px;
width: 100%;
margin: 0;
font-size: 0;
}
<div class="i_timeliner">
<ul>
<li>
<div class="i_timeliner_box">
<h2>1</h2>
<p></p>
</div>
</li>
<li>
<div class="i_timeliner_box">
<h2>2</h2>
<p></p>
</div>
</li>
<li>
<div class="i_timeliner_box">
<h2>3</h2>
<p></p>
</div>
</li>
<li>
<div class="i_timeliner_box">
<h2>4</h2>
<p></p>
</div>
</li>
<li>
<div class="i_timeliner_box">
<h2>5</h2>
<p></p>
</div>
</li>
<li></li>
</ul>
</div>