【问题标题】:Bootstrap - Getting my P (with typing effect) in the middle of a divBootstrap - 在 div 中间获取我的 P(具有打字效果)
【发布时间】:2020-08-07 09:36:54
【问题描述】:

我试图让我的具有打字效果的文本居中在这个 div 的中间,但我无法让它工作。在下面,您可以看到我尝试使用的代码,但它适合这项工作。它仍然会在 div 的左侧显示文本。

<header class="masthead text-white text-center">
    <div class="overlay"></div>
         <div class="container">
              <div class="row">
                  <div class="col-xl-10 css-typing mx-auto ">
                      <p>
                         Hey! Ik ben 
                      </p>
                      <p>
                         Tom Faas
                      </p>
                  </div>
              </div>
        </div>
</header>

CSS 代码:

.css-typing p {
  border-right: .15em solid white;
  font-family: "Courier";
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;

}
.css-typing p:nth-child(1) {
    width: 7.3em;
    text-align: center;
    -webkit-animation: type 2s steps(40, end);
    animation: type 2s steps(40, end),
    blinkTextCursor 500ms steps(44) infinite normal;;
    -webkit-animation-fill-mode: forwards;
    animation-fill-mode: forwards;
}

.css-typing p:nth-child(2) {
    width: 7.3em;
    font-size: 200%;
    text-align: center;
    opacity: 0;
    -webkit-animation: type2 2s steps(40, end);
    animation: type2 2s steps(40, end),
    blinkTextCursor 500ms steps(44) infinite normal;;
    -webkit-animation-delay: 2s;
    animation-delay: 2s;
    animation-fill-mode: forwards;
}

@keyframes type {
  0% {
    width: 0;
  }
  99.9% {
    border-right: .15em solid white;
  }
  100% {
    opacity: 1;
    border: none;
  }
}

@-webkit-keyframes type {
  0% {
    width: 0;
  }
  99.9% {
    border-right: .15em solid white;
  }
  100% {
    opacity: 1;
    border: none;
  }
}

@keyframes type2 {
  0% {
    width: 0;
  }
  1% {
    opacity: 1;
  }
  99.9% {
    border-right: .15em solid white;
  }
  100% {
    opacity: 1;
    border: none;
  }
}

@-webkit-keyframes type2 {
  0% {
    width: 0;
  }
  1% {
    opacity: 1;
  }
  99.9% {
    border-right: .15em solid white;
  }
  100% {
    opacity: 1;
    border: none;
  }
}

正如您在示例中看到的那样,我尝试使用 mx-auto 标签,但它不会使文本居中,并且仍会将其放在 div 的左侧。

【问题讨论】:

    标签: html css bootstrap-4 center


    【解决方案1】:

    在您使用mx-auto 的CSS 属性下方添加。它将使您的文本居中。

    display: flex;
    flex-direction: column;
    align-items: center;
    

    【讨论】:

    • 如果您喜欢我的回答或从我的回答中得到任何帮助,请不要忘记考虑投票并通过单击右箭头将此答案作为您的最佳答案,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 2021-10-11
    • 2017-10-14
    相关资源
    最近更新 更多