我想要垂直线来连接图像(从中间),并且我不想在第一张图像上方添加线。

我在这里添加了http://jsfiddle.net/cd465nj3/链接

  Image 1
     |
     |
  Image 2
     |
     |
  Image 3

我如何修改上面的代码以从中间获取垂直线?
任何帮助,将不胜感激!
谢谢!!

.box {
    width:662px;
    margin:0 auto;

}

.box li {
   display: flex;
  align-content: center;
  flex-wrap: wrap;
  flex-direction:column;

}

img{
  height: 100px;
  width:100px;
  border-radius: 50%;
}

.line {
     border-left: 6px solid green;
     height: 100px;
}
<div class="box">
    <ul>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li ><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
    </ul>
</div>

最佳答案

您可以添加以下样式:

ul {
  display: inline-block;
}
.line {
  display: block;
  margin: 0 auto;
}

ul li:first-child > span.line { display: none; }

工作代码示例:

.box {
    width:662px;
    margin:0 auto;

}

.box li {
   display: flex;
  align-content: center;
  flex-wrap: wrap;
  flex-direction:column;

}

img{
  height: 100px;
  width:100px;
  border-radius: 50%;
}

.line {
     border-left: 6px solid green;
     height: 100px;
}
ul {
    display: inline-block;
}
.line {
    display: block;
    margin: 0 auto;
}

ul li:first-child > span.line { display: none; }
<div class="box">
    <ul>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li ><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
        <li><span class="line"></span><img src="http://t2.gstatic.com/images?q=tbn:ANd9GcSZ3KCafAVUhanaeaAsG0Q8lzdKKMOo7TP3H1W4TcMEcpVqtKTPVA&t=1" /></li>
    </ul>
</div>

关于javascript - 如何在中心上方的图像上方绘制一条垂直线?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52400004/

10-13 01:45