【问题标题】:Jumbotron breaks navbar on mobile websiteJumbotron 打破移动网站上的导航栏
【发布时间】:2019-07-04 22:23:32
【问题描述】:

Bootstrap Jumbotrons 从我网站上的容器中消失,这意味着移动版本上的导航栏不会填满屏幕。我没有 jumbotron 的其他页面不会出现此问题。

我尝试使用卡片代替,但是当我将它放在除文本之外的任何内容时会出现一些问题

<div class="row">
    <div class="jumbotron col-lg-8 col-md-12"
        style='margin-left: 15px; margin-top: 15px; padding-top: 10px; padding-bottom: 10px; margin-bottom: 10px;'>
        <h1 class="display-3">
            <b>Welcome to SkyWars.fun</b>
        </h1>
        <p class="lead">We focus on updating regularly, and we listen close to
            our community suggestions.</p>
        <hr class="my-4">
        <p>We have a perk system, comparable with kits or abillities. Any
            player can enable 3 perks at once. These perks give small advantages
            for your gameplay. Choose wisely, and adapt with your perks! Happy
            SkyWars! And have fun!</p>
        <p class="lead">
            <a class="btn btn-primary btn-lg" href="../tips" role="button">Tips
                and tricks</a>
        </p>
    </div>
</div>

对于导航栏

<nav class="navbar navbar-expand-lg navbar-dark bg-primary" role="navigation">
    <a class="navbar-brand" href="../">IP: SkyWars.fun</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse"
        data-target="#navbarColor01" aria-controls="navbarColor01"
        aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarColor01">
        <ul class="navbar-nav mr-auto">
            <li
                class="nav-item <?php if($_SERVER['REQUEST_URI'] === '/') echo 'active' ?>"><a
                class="nav-link" href="https://www.skywars.fun/" title="Go to the main page">Home </a></li>
            <li class="nav-item <?php if(isPage('/about/')) echo 'active' ?>"><a
                class="nav-link" href="https://www.skywars.fun/about" title="Information about SkyWars.fun">About</a></li>
            <li class="nav-item <?php if(isPage('/tips/')) echo 'active' ?>"><a
                class="nav-link" href="https://www.skywars.fun/tips" title="Tips and Tricks">Tips</a></li>
            <li class="nav-item <?php if(isPage('/donate/')) echo 'active' ?>"><a
                class="nav-link" href="https://www.skywars.fun/donate" title="Donate">Donate</a></li>
            <li class="nav-item <?php if(isPage('/search/')) echo 'active' ?>"><a
                class="nav-link" href="https://www.skywars.fun/search" title="Leaderboard">Leaderboard</a></li>
        </ul>
        <form class="form-inline my-2 my-lg-0" action="../search" title="Lookup player">
            <input class="form-control mr-sm-2" type="text" name="player"
                placeholder="Search player">
            <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
        </form>
    </div>
</nav>

问题的图片

https://drive.google.com/file/d/0ByAYcnq6pPDmNlJsUUNBbkM1aFRITEQ5TUF4U0JxWXpOYVBV/view?usp=sharing https://drive.google.com/file/d/0ByAYcnq6pPDmcnVsbTNMbkI2MnlNdmZocmtXV0FWbXpmUTdN/view?usp=sharing

【问题讨论】:

  • 欢迎。请创建一个minimal reproducible example - 并确保包含除 bootstrap 4 之外的任何样式......
  • @cale_b 我​​不确定如何在不遗漏任何内容的情况下最小化代码。我添加了图片
  • 请求不是最小化的问题,是你需要给我们一个完整的例子。包含给出完整、可运行示例所需的最少代码。查看如何制作runnable snippet
  • @cale_b 问题是模拟中不会出现这个问题。
  • 那么您希望任何人都能为您解决问题?如果您无法将代码简化为可重现的最小示例并与我们分享,那么您迄今为止共享的代码如何让我们对其进行故障排除?听起来您认为您需要有人查看您的整个页面/代码,这在 SO 上是不切实际的。

标签: html css bootstrap-4


【解决方案1】:

* {
   margin: 0;
   padding: 0;
}

.banner {
    background: #e9ecef;
}

@media only screen and (max-width: 767px) {
.display-3 {
    font-size: 2rem !important;
}
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-primary" role="navigation">
      <a class="navbar-brand" href="../">IP: SkyWars.fun</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse"
        data-target="#navbarColor01" aria-controls="navbarColor01"
        aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarColor01">
        <ul class="navbar-nav mr-auto">
          <li
            class="nav-item <?php if($_SERVER['REQUEST_URI'] === '/') echo 'active' ?>"><a class="nav-link" href="https://www.skywars.fun/" title="Go to the main page">Home </a></li>
          <li class="nav-item <?php if(isPage('/about/')) echo 'active' ?>"><a class="nav-link" href="https://www.skywars.fun/about" title="Information about SkyWars.fun">About</a></li>
          <li class="nav-item <?php if(isPage('/tips/')) echo 'active' ?>"><a class="nav-link" href="https://www.skywars.fun/tips" title="Tips and Tricks">Tips</a></li>
          <li class="nav-item <?php if(isPage('/donate/')) echo 'active' ?>"><a class="nav-link" href="https://www.skywars.fun/donate" title="Donate">Donate</a></li>
          <li class="nav-item <?php if(isPage('/search/')) echo 'active' ?>"><a class="nav-link" href="https://www.skywars.fun/search" title="Leaderboard">Leaderboard</a></li>
        </ul>
        <form class="form-inline my-2 my-lg-0" action="../search" title="Lookup player">
          <input class="form-control mr-sm-2" type="text" name="player"
            placeholder="Search player">
          <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
        </form>
      </div>
    </nav>
    <section class="banner">
      <div class="container-fluid">
          <div class="row">
            <div class="col-12">
              <div class="jumbotron">
                <h1 class="display-3">
                  <b>Welcome to SkyWars.fun</b>
                </h1>
                <p class="lead">We focus on updating regularly, and we listen close to
                  our community suggestions.
                </p>
                <hr class="my-4">
                <p>We have a perk system, comparable with kits or abillities. Any
                  player can enable 3 perks at once. These perks give small advantages
                  for your gameplay. Choose wisely, and adapt with your perks! Happy
                  SkyWars! And have fun!
                </p>
                <p class="lead">
                  <a class="btn btn-primary btn-lg" href="../tips" role="button">Tips
                  and tricks</a>
                </p>
              </div>
            </div>
        </div>
      </div>
    </section>
    <script
      src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  </body>
</html>

我已经减小了小型设备的字体大小,它正在脱离容器。在使用主类之前,还要使用 .container > .row > .col-lg-12 [仅举例]。参考通过https://getbootstrap.com/docs/4.1/layout/grid/这个链接。希望能解决你的问题

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 2011-12-11
    • 1970-01-01
    • 2022-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多