tra*_*ism 20 css list html-lists
我如何在无序列表中绘制子弹之间的垂直线,如下所示:
请注意,该行在最后一个列表项目符号处停止.我正在使用list-style:none;和图像作为子弹.HTML看起来像这样:
<ul class="experiences">
<!-- Experience -->
<li class="green">
<div class="where">New York Times</div>
<h3 class="what green">Senior Online Editor</h3>
<div class="when">2012 - Present</div>
<p class="description">Jelly-o pie chocolate cake...</p>
</li>
...
Run Code Online (Sandbox Code Playgroud)
要求的CSS代码:
/* Experiences */
ul.experiences {
padding-left: 15px;
margin-top: -1px;
}
ul.experiences li {
padding-left: 33px;
margin-bottom: 2.5em;
list-style: none;
background: url('../img/misc/list-bullet-darkgray.png') no-repeat;
}
ul.experiences li.green {
background: url('../img/misc/list-bullet-green.png') no-repeat;
}
ul.experiences li.blue {
background: url('../img/misc/list-bullet-blue.png') no-repeat;
}
ul.experiences li.pink {
background: url('../img/misc/list-bullet-pink.png') no-repeat;
}
.where {
font-size: 1.2857em; /* 18/16 -> 18px */
font-weight: 300;
display: inline;
margin-right: 0.5em;
}
.what {
font-size: 0.75em; /* 12/16 -> 12px */
font-weight: 700;
text-transform: uppercase;
color: #fff;
background-color: #444444;
display: inline-block;
padding: 0 12px;
margin: -5px 0.5em 0 0 !important;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
.what.green {
background-color: #c4df9b;
}
.what.blue {
background-color: #6dcff6;
}
.what.pink {
background-color: #f06eaa;
}
.when {
float: right;
color: #b9b9b9;
font-style: italic;
}
.description {
display: block;
margin-top: 0.5em;
}
Run Code Online (Sandbox Code Playgroud)
sbi*_*nko 22
我怀疑这是否可以通过边界和"摆弄利润"来实现,正如其他人所暗示的那样,至少我没有运气这样做.
此解决方案使用CSS生成的内容(:before和:after)来绘制项目符号和行.它允许高度自定义并保持标记清洁,但请注意浏览器支持.
JSFiddle(滚动CSS直到/* BORDERS AND BULLETS */评论)
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 */
}
Run Code Online (Sandbox Code Playgroud)
注意:如果行的border-color指定了alpha通道,则第一个和第二个元素的边界之间的重叠将是显而易见的.
由于这里没有太多好的答案,我想我应该添加我的解决方案:
我利用相对位置,并在最后一项上添加白色遮罩以隐藏溢出。适用于移动视图和项目高度的变化。
超文本标记语言
<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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
演示 http://jsfiddle.net/cfzsgkyn/