How would I go about drawing a vertical line between the bullets in an unordered list, like so:
Notice that the line stops at the last list bullet. I\'m usi
ul.experiences li {
padding-left: 33px;
margin-bottom: 2.5em;
list-style: none;
background: url('../img/misc/list-bullet-darkgray.png') no-repeat;
border-left: 1px solid #yourcolor;
}
And then I would just use padding and margins to align it and to stop the last one from extending:
ul.experiences li:last-child {
padding-left: 33px;
margin-bottom: 2.5em;
list-style: none;
background: url('../img/misc/list-bullet-darkgray.png') no-repeat;
border-left: none;
}
The last child selector does not work in versions of IE < 7
DEMO
Probably a bit old now but here is a way you can do this. It requires a bit more markup to create styles and control the heights of elements (I used spans but you can use tags ):
ol,
ul {
list-style: none;
}
li {
display: flex;
flex-flow: row;
min-height: 100px;
position: relative;
}
span.number {
margin-right: 100px;
text-align: center;
width: 1em;
height: 1em;
background-color: red;
border-radius: 50%;
z-index: 1;
}
span.line {
position: absolute;
height: 100%;
border: solid black 0.1em;
top: 0.5em;
left: 0.45em;
}
li:last-child span.line {
display: none;
}
}
span.blob {}
<ul>
<li><span class='line'></span><span class='number'>1</span>
<div class='blob'>Hello</div>
</li>
<li><span class='number'>2</span>
<div class='blob'>Goodbye</div>
</li>
</ul>
http://jsfiddle.net/efava0je/
You need to add a inner and outter div and then play with margins. Here is what i mean
DEMO: http://jsfiddle.net/kevinPHPkevin/N9svF/
ul {
padding-left:14px;
margin-top:-6px;
margin-bottom:-6px;
padding-bottom:0;
}
#mainDiv {
height: 200px;
width:200px;
position: relative;
}
#borderLeft {
border-left: 2px solid #f51c40;
position: absolute;
top: 25px;
}
I doubt that this is achievable using just borders and "fiddling with margins" as others have suggested, at least I've had no luck in doing so.
This solution uses CSS-generated content (:before
and :after
) to draw bullets and lines. It allows for
a high degree of customization and it keeps the markup clean, but note the browser support.
JSFiddle (scroll through CSS until the /* BORDERS AND BULLETS */
comment)
ul.experiences li {
position:relative; /* so that pseudoelements are positioned relatively to their "li"s*/
/* use padding-bottom instead of margin-bottom.*/
margin-bottom: 0; /* This overrides previously specified margin-bottom */
padding-bottom: 2.5em;
}
ul.experiences li:after {
/* bullets */
content: url('http://upload.wikimedia.org/wikipedia/commons/thumb/3/30/RedDisc.svg/20px-RedDisc.svg.png');
position: absolute;
left: -26px; /*adjust manually*/
top: 0px;
}
ul.experiences li:before {
/* lines */
content:"";
position: absolute;
left: -16px; /* adjust manually */
border-left: 1px solid black;
height: 100%;
width: 1px;
}
ul.experiences li:first-child:before {
/* first li's line */
top: 6px; /* moves the line down so that it disappears under the bullet. Adjust manually */
}
ul.experiences li:last-child:before {
/* last li's line */
height: 6px; /* shorten the line so it goes only up to the bullet. Is equal to first-child:before's top */
}
NOTE: if the line's border-color
has an alpha-channel specified, the overlap between first and second elements' borders will be noticeable.
Since there aren't many good answers here, I figured I'd add my solution:
I take advantage of position relative and include a white mask on the last item to hide the overflow. Works in mobile view and variation of the item heights.
HTML
<div class="list-wrapper">
<div class="red-line"></div>
<div class="list-item-wrapper">
<div class="list-bullet">1</div>
<div class="list-item">
<div class="list-title">ITEM</div>
<div class="list-text">Text</div>
</div>
</div>
<div class="list-item-wrapper">
<div class="list-bullet">2</div>
<div class="list-item">
<div class="list-title">ITEM</div>
<div class="list-text">Text</div>
</div>
</div>
<div class="list-item-wrapper">
<div class="list-bullet">3</div>
<div class="list-item">
<div class="list-title">ITEM</div>
<div class="list-text">Text</div>
</div>
<div class="white-line"></div>
</div>
</div>
CSS
.list-wrapper {
position:relative;
}
.list-item-wrapper {
margin-top:10px;
position:relative;
}
.list-bullet {
float:left;
margin-right:20px;
background:#FF4949;
height:30px;
width:30px;
line-height:30px;
border-radius:100px;
font-weight:700;
color:white;
text-align:center;
}
.list-item {
display:table-row;
vertical-align:middle;
}
.list-title {
font-weight:700;
}
.list-text {
font-weight:400;
}
.red-line {
background:#FF4949;
z-index:-1;
width:1px;
height:100%;
position:absolute;
left:15px;
}
.white-line {
background:#FFF;
z-index:-1;
top:0px;
width:1px;
height:100%;
position:absolute;
left:15px;
}
DEMO http://jsfiddle.net/cfzsgkyn/