Cách tạo: Dòng thời gian

Học cách sử dụng CSS để tạo dòng thời gian tương ứng.

Dòng thời gian

2017

Lorem ipsum dolor sit amet, quo ei simul congue exerci, ad nec admodum perfecto mnesarchum, vim ea mazim fierent detracto. Ea quis iuvaret expetendis his, te elit voluptua dignissim per, habeo iusto primis ea eam.

2016

Lorem ipsum dolor sit amet, quo ei simul congue exerci, ad nec admodum perfecto mnesarchum, vim ea mazim fierent detracto. Ea quis iuvaret expetendis his, te elit voluptua dignissim per, habeo iusto primis ea eam.

2015

Lorem ipsum dolor sit amet, quo ei simul congue exerci, ad nec admodum perfecto mnesarchum, vim ea mazim fierent detracto. Ea quis iuvaret expetendis his, te elit voluptua dignissim per, habeo iusto primis ea eam.

Thử ngay

Cách tạo dòng thời gian

Bước 1 - Thêm HTML:

<div class="timeline">
  <div class="container left">
    <div class="content">
      <h2>2017</h2>
      <p>Lorem ipsum..</p>
    </div>
  </div>
  <div class="container right">
    <div class="content">
      <h2>2016</h2>
      <p>Lorem ipsum..</p>
    </div>
  </div>
</div>

Bước 2 - Thêm CSS:

* {
  box-sizing: border-box;
}
/* Đặt màu nền */
body {
  background-color: #474e5d;
  font-family: Helvetica, sans-serif;
}
/* Thực tế dòng thời gian (thước đo thẳng đứng) */
.timeline {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
}
/* Thực tế dòng thời gian (thước đo thẳng đứng) */
.timeline::after {
  content: '';
  position: absolute;
  width: 6px;
  background-color: white;
  top: 0;
  bottom: 0;
  left: 50%;
  margin-left: -3px;
}
/* Hộp bao bọc nội dung */
.container {
  padding: 10px 40px;
  position: relative;
  background-color: inherit;
  width: 50%;
}
/* Điểm tròn trên dòng thời gian */
.container::after {
  content: '';
  position: absolute;
  width: 25px;
  height: 25px;
  right: -17px;
  background-color: white;
  border: 4px solid #FF9F55;
  top: 15px;
  border-radius: 50%;
  z-index: 1;
}
/* Đặt hộp chứa ở bên trái */
.left {
  left: 0;
}
/* Đặt hộp ở bên phải */
.right {
  left: 50%;
}
/* Thêm mũi tên vào hộp bên trái (điểm sang bên phải) */
.left::before {
  content: " ";
  height: 0;
  position: absolute;
  top: 22px;
  width: 0;
  z-index: 1;
  right: 30px;
  border: medium solid white;
  border-width: 10px 0 10px 10px;
  border-color: transparent transparent transparent white;
}
/* Thêm mũi tên vào hộp bên phải (điểm sang bên trái) */
.right::before {
  content: " ";
  height: 0;
  position: absolute;
  top: 22px;
  width: 0;
  z-index: 1;
  left: 30px;
  border: medium solid white;
  border-width: 10px 10px 10px 0;
  border-color: transparent white transparent transparent;
}
/* Sửa lỗi vị trí hình tròn của hộp bên phải */
.right::after {
  left: -16px;
}
/* Nội dung thực tế */
.content {
  padding: 20px 30px;
  background-color: white;
  position: relative;
  border-radius: 6px;
}
/* Truy vấn truyền thông - đường thời gian phản hồi trên màn hình có độ rộng nhỏ hơn 600 pixel */
@media screen and (max-width: 600px) {
/* Đặt timeline sang bên trái */
  .timeline::after {
    left: 31px;
  }
/* Hộp rộng toàn bộ */
  .container {
    width: 100%;
    padding-left: 70px;
    padding-right: 25px;
  }
/* Đảm bảo rằng tất cả các mũi tên đều chỉ về bên trái */
  .container::before {
    left: 60px;
    border: medium solid white;
    border-width: 10px 10px 10px 0;
    border-color: transparent white transparent transparent;
  }
/* Đảm bảo rằng tất cả các hình tròn đều ở cùng một vị trí */
  .left::after, .right::after {
    left: 15px;
  }
/* Làm cho tất cả các hộp bên phải có hành vi giống như hộp bên trái */
  .right {
    left: 0%;
  }
}

Thử ngay