Bootstrap垂直时间轴到水平时间轴

时间:2018-02-15 17:13:26

标签: html css twitter-bootstrap twitter-bootstrap-3

我创建了一个垂直时间轴,需要将其完全更改为水平时间轴我试图将其设置为水平但不会按预期工作。

发布完整的CSS& HTML代码还链接到当前进度的codepen。

此外,时间轴需要在水平视图中响应。

链接

https://codepen.io/anon/pen/yvPLrP

#Timline {
  background-color: #FFFFFF;
}

.Timline-wrapper {
  position: relative;
  clear: both;
  overflow: hidden;
}

.Timline-wrapper:nth-of-type(odd) .Timline-item {
  padding-left: 100px;
  padding-right: 0;
  padding-bottom: 50px;
  float: right;
}

.Timline-wrapper:nth-of-type(odd) .Timline-box:after {
  left: -20px;
  right: auto;
  border-color: transparent;
  text-align: left;
  border-right: 10px solid #fff;
  border-left-color: transparent !important;
}

.Timline-wrapper:nth-of-type(odd) .Timline-icon {
  right: auto;
  left: -32px;
}

.Timline-wrapper:nth-of-type(odd) .Timline-year {
  text-align: right;
  right: 140%;
  left: auto;
}

.Timline-holder:before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  margin-left: -4px;
  height: 100%;
  width: 4px;
  background: #939393;
  opacity: 0.5;
}

.Timline-item {
  padding-right: 100px;
  padding-bottom: 50px;
  padding-top: 50px;
}

.Timline-year {
  top: 40px;
  position: absolute;
  width: 100%;
  left: 140%;
}

.Timline-year>* {
  margin: 0;
}

.Timline-icon {
  border-radius: 50%;
  background: #fff;
  position: absolute;
  width: 60px;
  height: 60px;
  right: -28px;
  top: 72px;
  z-index: 9;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.3s ease-in-out;
}

.Timline-icon:before {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.Timline-icon:hover {
  color: #E3000F;
  border: 2px solid #E3000F;
  transform: translateY(-6px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
}

.Timline-box {
  background-color: #fff;
  padding: 15px;
  position: relative;
}

.Timline-box h3,
.Timline-box h5 {
  text-transform: capitalize;
}

.Timline-box:after {
  content: "";
  display: block;
  position: absolute;
  right: -20px;
  top: 40px;
  border: 10px solid transparent;
  border-left: 10px solid #fff;
}

.Timline-box:hover {
  cursor: pointer;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
}

.Timline-box:hover+.Timline-icon {
  color: #E3000F;
  border: 2px solid #E3000F;
  transform: translateY(-6px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
}

.Timline-box {
  background-color: #fff;
  padding: 15px;
}


/* Timline  Responsive */

@media (min-width: 992px) and (max-width: 1024px) {
  .Timline-year {
    left: 152%;
  }
  .Timline-wrapper:nth-of-type(odd) .Timline-year {
    right: 152%;
  }
}

@media (max-width: 768px) {
  .Timline-item {
    padding-right: 15px;
    margin-left: 65px;
    padding-top: 20px;
  }
  .Timline-holder:before {
    left: 37px;
  }
  .Timline-icon {
    left: -60px;
    right: auto;
    top: 42px;
  }
  .Timline-year {
    position: relative;
    top: 0;
    left: 0;
  }
  .Timline-box:after {
    left: -20px;
    right: auto;
    border-color: transparent;
    text-align: left;
    border-right: 10px solid #fff;
    border-left-color: transparent !important;
  }
  .Timline-wrapper:nth-of-type(odd) .Timline-item {
    padding-right: 15px;
    padding-left: 15px;
    margin-left: 65px;
    float: none;
  }
  .Timline-wrapper:nth-of-type(odd) .Timline-icon {
    left: -60px;
    right: auto;
  }
  .Timline-wrapper:nth-of-type(odd) .Timline-year {
    position: relative;
    top: 0;
    left: 0;
    text-align: left;
  }
}
<!-- Timline Section -->
<section id="Timline">
  <div class="container">
    <div class="section-content">
      <div class="row">
        <!-- Section Title -->
        <div class="col-md-12 section-title text-center">
          <span class="divider center"></span>
          <h2>Timline</h2>
        </div>
        <!-- End of Section Title -->
        <!-- Timline-1 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class="Timline-box" data-aos="fade-right">
                  <h3>One</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-paint-brush"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-1 -->
        <!-- Timline-2 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Two</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-star"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-2 -->
        <!-- Timline-3 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Three</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-3 -->
        <!-- Timline-4 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Four</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-star"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-4 -->
        <!-- Timline-5 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Five</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-paint-brush"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-5 -->
        <!-- Timline-6 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Six</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-star"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-6 -->
        <!-- Timline-7 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Seven</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-7 -->
        <!-- Timline-8 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Eight</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-star"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-8 -->
        <!-- Timline-9 -->
        <div class="Timline-wrapper">
          <div class="col-md-12 Timline-holder">
            <div class="row">
              <div class="col-md-6 col-sm-12 Timline-item">
                <div class=" Timline-box" data-aos="fade-right">
                  <h3>Nine</h3>
                </div>
                <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
              </div>
            </div>
          </div>
        </div>
        <!-- End of Timline-9 -->

      </div>
    </div>
  </div>
</section>
<!-- End of Timline Section -->

1 个答案:

答案 0 :(得分:0)

您可以根据您的要求修改此内容

/* Timeline */

.timeline,
.timeline-horizontal {
  list-style: none;
  padding: 20px;
  position: relative;
}

.timeline:before {
  top: 40px;
  bottom: 0;
  position: absolute;
  content: " ";
  width: 3px;
  background-color: #eeeeee;
  left: 50%;
  margin-left: -1.5px;
}

.timeline .timeline-item {
  margin-bottom: 20px;
  position: relative;
}

.timeline .timeline-item:before,
.timeline .timeline-item:after {
  content: "";
  display: table;
}

.timeline .timeline-item:after {
  clear: both;
}

.timeline .timeline-item .timeline-badge {
  color: #fff;
  width: 54px;
  height: 54px;
  line-height: 52px;
  font-size: 22px;
  text-align: center;
  position: absolute;
  top: 18px;
  left: 50%;
  margin-left: -25px;
  background-color: #7c7c7c;
  border: 3px solid #ffffff;
  z-index: 100;
  border-top-right-radius: 50%;
  border-top-left-radius: 50%;
  border-bottom-right-radius: 50%;
  border-bottom-left-radius: 50%;
}

.timeline .timeline-item .timeline-badge i,
.timeline .timeline-item .timeline-badge .fa,
.timeline .timeline-item .timeline-badge .glyphicon {
  top: 2px;
  left: 0px;
}

.timeline .timeline-item .timeline-badge.primary {
  background-color: #1f9eba;
}

.timeline .timeline-item .timeline-badge.info {
  background-color: #5bc0de;
}

.timeline .timeline-item .timeline-badge.success {
  background-color: #59ba1f;
}

.timeline .timeline-item .timeline-badge.warning {
  background-color: #d1bd10;
}

.timeline .timeline-item .timeline-badge.danger {
  background-color: #ba1f1f;
}

.timeline .timeline-item .timeline-panel {
  position: relative;
  width: 46%;
  float: left;
  right: 16px;
  border: 1px solid #c0c0c0;
  background: #ffffff;
  border-radius: 2px;
  padding: 20px;
  -webkit-box-shadow: 0 1px 6px rgba(0, 0, 0, 0.175);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.175);
}

.timeline .timeline-item .timeline-panel:before {
  position: absolute;
  top: 26px;
  right: -16px;
  display: inline-block;
  border-top: 16px solid transparent;
  border-left: 16px solid #c0c0c0;
  border-right: 0 solid #c0c0c0;
  border-bottom: 16px solid transparent;
  content: " ";
}

.timeline .timeline-item .timeline-panel .timeline-title {
  margin-top: 0;
  color: inherit;
}

.timeline .timeline-item .timeline-panel .timeline-body>p,
.timeline .timeline-item .timeline-panel .timeline-body>ul {
  margin-bottom: 0;
}

.timeline .timeline-item .timeline-panel .timeline-body>p+p {
  margin-top: 5px;
}

.timeline .timeline-item:last-child:nth-child(even) {
  float: right;
}

.timeline .timeline-item:nth-child(even) .timeline-panel {
  float: right;
  left: 16px;
}

.timeline .timeline-item:nth-child(even) .timeline-panel:before {
  border-left-width: 0;
  border-right-width: 14px;
  left: -14px;
  right: auto;
}

.timeline-horizontal {
  list-style: none;
  position: relative;
  padding: 20px 0px 20px 0px;
  display: inline-block;
}

.timeline-horizontal:before {
  height: 3px;
  top: auto;
  bottom: 26px;
  left: 56px;
  right: 0;
  width: 100%;
  margin-bottom: 20px;
}

.timeline-horizontal .timeline-item {
  display: table-cell;
  height: 280px;
  width: 20%;
  min-width: 320px;
  float: none !important;
  padding-left: 0px;
  padding-right: 20px;
  margin: 0 auto;
  vertical-align: bottom;
}

.timeline-horizontal .timeline-item .timeline-panel {
  top: auto;
  bottom: 64px;
  display: inline-block;
  float: none !important;
  left: 0 !important;
  right: 0 !important;
  width: 100%;
  margin-bottom: 20px;
}

.timeline-horizontal .timeline-item .timeline-panel:before {
  top: auto;
  bottom: -16px;
  left: 28px !important;
  right: auto;
  border-right: 16px solid transparent !important;
  border-top: 16px solid #c0c0c0 !important;
  border-bottom: 0 solid #c0c0c0 !important;
  border-left: 16px solid transparent !important;
}

.timeline-horizontal .timeline-item:before,
.timeline-horizontal .timeline-item:after {
  display: none;
}

.timeline-horizontal .timeline-item .timeline-badge {
  top: auto;
  bottom: 0px;
  left: 43px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div class="page-header">
        <h1>Horizontal timeline</h1>
      </div>
      <div style="display:inline-block;width:100%;overflow-y:auto;">
        <ul class="timeline timeline-horizontal">
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>One</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Two</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Three</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Four</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Five</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Six</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Seven
                    </h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Eight</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
          <li class="timeline-item">
            <div class="col-md-12 Timline-holder">
              <div class="row">
                <div class="col-md-6 col-sm-12 Timline-item">
                  <div class=" Timline-box" data-aos="fade-right">
                    <h3>Nine</h3>
                  </div>
                  <i class=" Timline-icon fa fa-2x fa-lightbulb-o"></i>
                </div>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>