如何使用HTML和CSS在时间轴上放置现有列表元素?

时间:2017-05-25 18:24:07

标签: html css

我正在尝试构建一个类似于下图所示的时间轴: Example Timeline 我遇到的困难是构建时间轴的底部,其中图标由一条线连接,并且在每个事件的底部添加三角形。这是我目前的代码:

.navbar {
  margin-bottom: 0px;
}

.jumbotron {
  margin-bottom: 0px;
}

#timeline {
  list-style: none;
  white-space: nowrap;
  overflow: auto;
  padding-left: 0;
}

#timeline li {
  display: inline-block;
  padding: 1.5%;
  border: 1px solid #c0c0c0;
  border-radius: 5px;
  box-shadow: 1px 1px 6px #757677;
  margin-top: 2%;
  text-align: center;
  padding-bottom: 0;
  width: 45%;
}

#timeline li+li {
  margin-left: 2%;
}

#timeline li h3,
#timeline li em {
  display: block;
}

#timeline_header {
  padding-left: 0;
}

hr {
  width: 100%;
}

#triangle {
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 20px solid #757677;
  display: inline-block;
}
<!DOCTYPE html>
<html>

<head>
  <title>My Website</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  <link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>

  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <ul class="nav navbar-nav">
        <li><a href="#">LinkedIn</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </nav>

  <div class="jumbotron text-center">
    <h1>Welcome!</h1>
  </div>

  <div class="container">
    <div class="row">
      <div class="col-md-12" id="timeline_header">
        <h1>What I've Been Up To</h1>
      </div>
    </div>

    <!--Timeline-->
    <div class="row" style="overflow:auto">
      <hr>
      <ul id="timeline">
        <li>
          <h2>Job #2</h2>
          <em><h4>May 2016 - Present</h4></em>
          <h3>Software Developer</h3>
        </li>
        <div id="triangle"></div>
        <div class="timeline_icon">
          <img src="http://www.strohlsf.com/content/images/logos/logo_strohl_3.png" alt=""></div>

        <li>
          <h2>Job #1</h2>
          <em><h4>May 2012 - May 2016</h4></em>
          <h3>Software Developer</h3>
        </li>

        <li>
          <h2>Graduated from Colleg</h2>
          <em><h4>May 2012</h4></em>
          <h3>Bachelor's Degree</h3>
        </li>
      </ul>
    </div>
  </div>

  <hr>

  <footer>
    <p> Copyright &copy;
      <!--Script displays the current year-->
      <script type="text/javascript">
        var d = new Date()
        document.write(d.getFullYear())
      </script>
    </p>
  </footer>
</body>

</html>

我列表中的第一个列表元素是我尝试添加三角形和图标的尝试,但我无法弄清楚如何将三角形定位在底部边框上,以及如何将图标直接放置在三角形下方,图标之间有水平规则或其他线。

1 个答案:

答案 0 :(得分:1)

将三角形应用为伪元素:: after。图像与块对齐 - 操作起来会容易得多。修复了滚动视图仅在X中滚动,而不在Y轴滚动。该行是scrollview外部的对象,因为否则其长度仅限于可见区域并向左滚动视图。

<!DOCTYPE html>
<html>

<head>
  <title>My Website</title>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  <link href="styles.css" rel="stylesheet" type="text/css">
</head>

<body>

  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <ul class="nav navbar-nav">
        <li><a href="#">LinkedIn</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </nav>

  <div class="jumbotron text-center">
    <h1>Welcome!</h1>
  </div>

  <div class="container">
    <div class="row">
      <div class="col-md-12" id="timeline_header">
        <h1>What I've Been Up To</h1>
      </div>
    </div>

    <!--Timeline-->
    <div class="row" style="overflow:auto">
      <hr>
      <div class="timeline_ruler">
      <ul id="timeline">
        <li>
          <h2>Job #2</h2>
          <em><h4>May 2016 - Present</h4></em>
          <h3>Software Developer</h3>
          <img class="timeline_icon" src="http://www.strohlsf.com/content/images/logos/logo_strohl_3.png" alt="">
        </li>

        <li>
          <h2>Job #1</h2>
          <em><h4>May 2012 - May 2016</h4></em>
          <h3>Software Developer</h3>
          <img class="timeline_icon" src="http://www.strohlsf.com/content/images/logos/logo_strohl_3.png" alt="">
        </li>

       <li>
          <h2>Graduated from Colleg</h2>
          <em><h4>May 2012</h4></em>
          <h3>Bachelor's Degree</h3>
          <img class="timeline_icon" src="http://www.strohlsf.com/content/images/logos/logo_strohl_3.png" alt="">
        </li>
      </ul>
     
      
      
      </div>
      <div id=timeline_border></div>  
          
    </div>
  </div>

  <hr>

  <footer>
    <p> Copyright &copy;
      <!--Script displays the current year-->
      <script type="text/javascript">
        var d = new Date()
        document.write(d.getFullYear())
      </script>
    </p>
  </footer>
</body>

</html>
{{1}}