Bootstrap 尝试在div中将段落居中

llmtgqce  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(2)|浏览(171)

我对bootstrap是个新手,所以有一些事情我不明白。由于某种原因,在我的div中,我的段落没有居中。我做错了吗?
我试过你应该做的事了。(在最下面)

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<div class=c ontainer-fluid p-0>
  <!-- Adding the First Child Header Bar -->
  <nav class="navbar navbar-expand-lg bg-light">
    <div class="container-fluid">

      <img src="https://via.placeholder.com/80" class="logoimg">
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav me-auto mb-2 mb-lg-0">
          <li class="nav-item">
            <a class="nav-link active" aria-current="page" href="#">Home</a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="#">Link</a>
          </li>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdown</a>
            <ul class="dropdown-menu">
              <li><a class="dropdown-item" href="#">Action</a></li>
              <li><a class="dropdown-item" href="#">Another action</a></li>
              <li>
                <hr class="dropdown-divider">
              </li>
              <li><a class="dropdown-item" href="#">Something else here</a></li>
            </ul>
          </li>
          <li class="nav-item">
            <a class="nav-link disabled">Disabled</a>
          </li>
        </ul>
        <form class="d-flex" role="search">
          <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
          <button class="btn btn-outline-success" type="submit">Search</button><br><br>
        </form>
      </div>

    </div>
  </nav>
  <!-- Closing the First Child Header Bar -->

  <!-- Starting second bar-->
  <div class="bg-light">
    <h1 class="text-center">my website</h1>
    <p1 class="text-center">my website!</p1>
  </div>
  <!-- Ending second bar-->
44u64gxh

44u64gxh1#

可以在CSS中使用值为center的text-align属性。

div {
  text-align: center;
}
00jrzges

00jrzges2#

如果你正在使用bootstrap,那么我建议你按照bootstrap的规则把它放在一个容器class=" container"中,这样会把所有的东西都放在中心,如果需要的话,你可以应用你的自定义样式。

<div class="bg-light container ">
  <h1 class="text-center">my website</h1>
  <p1 class="text-center">my website!</p1>
</div>

或者,如果您将<p1>更改为<p>,则它会将您的.text-center类应用于它,而不会进行任何更改。

相关问题