响应式水平时间轴-Boostrap 4

时间:2019-04-13 16:55:43

标签: css bootstrap-4 timeline

我正在尝试制作响应式水平时间表。我将Boostrap 4用于时间表和项目。到目前为止,我已经提出了这段代码,并且在响应能力方面,它可以正常工作。

timeline.html

 .video-js .vjs-big-play-button .vjs-icon-placeholder:before {
content: "\f101"!important;
}

style.css

<div className="container timeline-container">
                    <div class="intro">
                        <div class="main-heading">
                            <div class="three-col top">
                                <div class="col">
                                    <div class="sub-heading">
                                        <div class="square">
                                            <div class="pic">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col">
                                    <div class="sub-heading">
                                        <div class="square">
                                            <div class="pic">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col">
                                    <div class="sub-heading">
                                        <div class="square">
                                            <div class="pic">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="main-heading">
                            <div class="three-col bottom">
                                <div className="wrapper-bottom">
                                    <div class="col">
                                        <div class="timeline-dot"> 
                                        </div>
                                        <div class="sub-heading">
                                            <div class="square">
                                                <div class="pic">
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col">
                                        <div class="timeline-dot"> 
                                        </div>
                                        <div class="sub-heading">
                                            <div class="square">
                                                <div class="pic">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col">
                                        <div class="timeline-dot"> 
                                        </div>
                                        <div class="sub-heading">
                                            <div class="square">
                                                <div class="pic">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

我的时间表如下:

enter image description here

我想更改两件事:

1)删除第一个点之前和最后一个点之后的行,这样时间线看起来像这样 enter image description here

2)使图片正方形具有响应性。

我通过使父.container.timeline-container{ position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } * { box-sizing: border-box; } .intro { position: relative; } .square { width: 100px; height: 100px; margin: 25px; transform:rotate(45deg); overflow: hidden; } .pic { background: url(http://placekitten.com/g/150/150); width: 150px; height: 150px; margin: -25px; -ms-transform: rotate(45deg); -webkit-transform: rotate(45deg); transform: rotate(45deg); } .timeline-dot { width: 10px; height: 10px; border-radius: 20px; margin: 0 auto; background: #CF4532; margin-top: -6px; } .main-heading { text-align: center; font-size: 30px; line-height: 30px; position: relative; } .three-col.bottom{ border-top: 2px solid #4A4A4A; } .three-col:after { display: block; clear: both; content: ''; } .three-col .col { float: left; width: 33.33%; position: relative; padding: 0 20px; } .sub-heading { position: relative; display: inline-block; padding: 20px 0; }

div

还有图片方块

.sub-heading {
    position: relative;
    display: inline-block;
    padding: 20px 0;
    width: 400px;
    height: 400px;   
}

但是它不起作用。任何建议表示赞赏。

1 个答案:

答案 0 :(得分:1)

1)您可以在每一列上使用css ::after伪类来实现这一点。从.three-col.bottom删除边框顶部,并使用.col将边框添加到顶行的每个::after

请注意CSS:

.three-col.top .col::after {
  content: "";
  position: absolute;
  display: block;
  left: 0;
  right: 0;
  bottom: 0;
  border-bottom: 2px solid #4A4A4A;
}

.three-col.top .col:first-child::after {
  left: 50%;
}

.three-col.top .col:last-child::after {
  right: 50%;
}

2)删除正方形div,不需要它。还要将.pic样式更改为

.pic {
  background: url(http://placekitten.com/g/150/150);
  width: 60px;
  height: 60px;
  -ms-transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
  margin: 25px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

对于响应式设计,您需要使用CSS媒体查询

  

https://www.w3schools.com/css/css3_mediaqueries.asp

所以您可以尝试这样的事情:

@media (min-width: 800px) {
  .pic {
    width: 150px;
    height: 150px;
  }
}

@media (min-width: 1024px) {
  .pic {
    width: 200px;
    height: 200px;
  }
}

@media (min-width: 1200px) {
  .pic {
    width: 250px;
    height: 250px;
  }
}

完整代码:

.container.timeline-container{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }

    * {
      box-sizing: border-box;
    }

    .intro {
      position: relative;
    }

    .square {
      width: 100px;
      height: 100px;
      margin: 25px;
      transform:rotate(45deg);
      overflow: hidden;
    }
    .pic {
      background: url(http://placekitten.com/g/150/150);
      width: 60px;
      height: 60px;
      -ms-transform: rotate(45deg);
      -webkit-transform: rotate(45deg);
      transform: rotate(45deg);
      margin: 25px;
      background-size: cover;
      background-position: center;
      background-repeat: no-repeat;
    }

    .timeline-dot {
      width: 10px;
      height: 10px;
      border-radius: 20px;
      margin: 0 auto;
      background: #CF4532;
      margin-top: -6px;
    }

    .main-heading {
      text-align: center;
      font-size: 30px;
      line-height: 30px;
      position: relative;
    }

    .three-col:after {
      display: block;
      clear: both;
      content: '';
    }

    .three-col .col {
      float: left;
      width: 33.33%;
      position: relative;
      padding: 0 20px;
    }

    .sub-heading {
      position: relative;
      display: inline-block;
      padding: 35px 0;

    }

    .three-col.top .col::after {
      content: "";
      position: absolute;
      background: #000;
      display: block;
      left: 0;
      right: 0;
      bottom: 0;
      border-bottom: 2px solid #4A4A4A;
    }

    .three-col.top .col:first-child::after {
      left: 50%;
    }

    .three-col.top .col:last-child::after {
      right: 50%;
    }

    @media (min-width: 576px) {
      .pic {
        width: 100px;
        height: 100px;
      }
    }

    @media (min-width: 800px) {
      .pic {
        width: 150px;
        height: 150px;
      }
    }

    @media (min-width: 1024px) {
      .pic {
        width: 200px;
        height: 200px;
      }
    }

    @media (min-width: 1200px) {
      .pic {
        width: 250px;
        height: 250px;
      }
    }
<div className="container timeline-container">
    <div class="intro">
      <div class="main-heading">
        <div class="three-col top">
          <div class="col">
            <div class="sub-heading">
              <div class="pic">
              </div>
            </div>
          </div>
          <div class="col">
            <div class="sub-heading">
              <div class="pic">
              </div>
            </div>
          </div>
          <div class="col">
            <div class="sub-heading">
              <div class="pic">
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="main-heading">
        <div class="three-col bottom">
          <div className="wrapper-bottom">
            <div class="col">
              <div class="timeline-dot">
              </div>
              <div class="sub-heading">
                <div class="pic">
                </div>
              </div>
            </div>

            <div class="col">
              <div class="timeline-dot">
              </div>
              <div class="sub-heading">
                <div class="pic">
                </div>
              </div>
            </div>
            <div class="col">
              <div class="timeline-dot">
              </div>
              <div class="sub-heading">
                <div class="pic">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>