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

标签 html css

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

.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>

我列表中的第一个列表元素是我尝试添加一个三 Angular 形和一个图标,但我不知道如何将三 Angular 形定位在底部边框上,以及如何将图标直接定位在三 Angular 形下方,在图标之间使用水平线或其他线。

最佳答案

三 Angular 形被应用为一个伪元素::after。图像与 block 对齐 - 操作起来会容易得多。将 ScrollView 固定为仅在 X 轴上滚动,而不是在 Y 轴上滚动。该线是 ScrollView 外部的对象,否则它的长度将限制在可见区域并随 View 向左滚动。

.navbar {
  margin-bottom: 0px;
}

.jumbotron {
  margin-bottom: 0px;
}

#timeline {
  list-style: none;
  padding-left: 0;
  padding-top: 40px;
  padding-bottom: 60px;
  position: relative;
}

#timeline_border {
  position: relative;
  top: -123px;
  display: block;
  width: 100%;
  height: 1px;
  border-top: 2px solid #ccc;
  z-index: -1;
}

#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%;
  position: relative;
}

#timeline > li:after {
  position: absolute;
  bottom: -20px;
  left: 40px;
  width: 0;
  height: 0;
  border-left: 20px solid transparent;
  border-right: 20px solid transparent;
  border-top: 20px solid #757677;
  display: block;
  content: "";
}

#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;
}

.timeline_ruler {
  white-space: nowrap;
   overflow-x: scroll;
   overflow-y: visible;
   display: block;
   height: auto;
   padding-bottom: 100px;
  
}

.timeline_icon {
  width: 80px;
  height: 80px;
  position: absolute;
  bottom: -102px;
  left: 20px;
}
<!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>

关于html - 如何使用 HTML 和 CSS 将现有列表元素放置在时间轴上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44187387/

相关文章:

html - 更改鼠标悬停在表中所有行上的背景颜色,这些行全部出现在使用 CSS 的特定类之后

html - 如何使cols之间的hr更长?

javascript - 如何使 Material-UI Table 保持动态高度的可滚动性?

html - 为什么高度 100% 对内容不起作用?

html - 有人知道解决 IE 7 CSS 问题的通用方法吗?

css - 格式化 CSS 有正确和错误的方法吗?

html - 根据浏览器大小对齐图像

javascript - 为什么将 "disabled"属性设置为 false 也会删除 "disabled"属性?

php - 停止在 div 内的表中滚动表标题 <th>

JavaScript getElementById().value 返回一个值,但在分配给变量时给出 "Undefined"