skip to Main Content

The section content is overlapping the navbar on certain screen sizes. I’m wondering why it’s doing that and how to prevent it. Do I need to wrap everything in a container or what’s the solution to this problem?

Using bootstrap v5.3.0-alpha1

also if i have a collapsed navbar, the button can’t be pressed bc the section is overlapping it, so fixing this would be helpful

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>test</title>

        <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link rel="stylesheet" href="{{ url_for('static', filename='css/dashboard.css') }}" />
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
    </head>
    <body>
        <nav class="navbar bg-body-tertiary">
            <div class="container-fluid">
                <a class="navbar-brand" href="#">
                    <img src={{url_for('static', filename='/images/logo.png')}} id="logo" alt="Logo" width="50" height="50" class="d-inline-block align-text-top" style="border-radius: 5px;">
                </a>

                <div class="btn-toolbar align-items-center justify-content-center" role="toolbar" aria-label="Toolbar with button groups">
                    <div class="btn-group me-2" role="group" aria-label="sign in">
                        <div class="dropdown">
                            <!-- dropdown-toggle -->
                            <button class="btn btn-primary" id="connect_wallet_button" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                Sign In
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end d-none" id="dropdown_menu">
                                <li><a class="dropdown-item" href="#" id="logout_button">Logout</a></li>
                            </ul>
                        </div>
                    </div>

                    <div class="btn-group me-2" role="group" aria-label="theme button">
                        <a href="/#">
                            <i class="bi bi-sun" id="theme_icon" style="font-size: 1.3rem;"></i>
                        </a>
                    </div>
                </div>
            </div>
        </nav>

        <div class="position-absolute top-50 start-50 translate-middle p-3">
            <div class="card">
                <div class="card-body">
                    <h3 class="card-title text-center">test form</h3>

                    <form class="needs-validation" id="form" action="/form" method="post">
                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>

                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>
                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>

                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>

                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>

                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>

                        <div class="mb-3">
                            <label for="name" class="form-label">test</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>

                        <div class="mb-3">
                            <div class="form-check">
                                <input class="form-check-input" type="checkbox" id="test" value="False" name="test" required>
                                <label class="form-check-label" for="test">
                                    ???
                                </label>
                            </div>
                        </div>
        
                        <div class="d-none" id="form_button_group">
                            <button type="button" class="btn btn-secondary" id="clear_button">Clear</button>
                            <button type="submit" class="btn btn-primary" id="submit_button">Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>



        <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
        <script type="text/javascript" src="{{ url_for('static', filename='js/dashboard.js') }}"></script>
        <script type="application/javascript" src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"></script>
    </body>
</html>

2

Answers


  1. This setup has a number of issues and I wasn’t sure which you wanted to address. If all you’re wanting to know is how to adjust what’s on top, it’s the z-index setting. You can style your element with z-index to control what is displayed on top. I added a foreground class in your code.

    <!doctype html>
    <style>
        .foreground {
            z-index: 50;
        }
    </style>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>test</title>
    
            <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
            <link rel="stylesheet" href="{{ url_for('static', filename='css/dashboard.css') }}" />
            <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
        </head>
        <body>
            <nav class="navbar bg-body-tertiary foreground">
                <div class="container-fluid">
                    <a class="navbar-brand" href="#">
                        <img src={{url_for('static', filename='/images/logo.png')}} id="logo" alt="Logo" width="50" height="50" class="d-inline-block align-text-top" style="border-radius: 5px;">
                    </a>
    
                    <div class="btn-toolbar align-items-center justify-content-center" role="toolbar" aria-label="Toolbar with button groups">
                        <div class="btn-group me-2" role="group" aria-label="sign in">
                            <div class="dropdown">
                                <!-- dropdown-toggle -->
                                <button class="btn btn-primary" id="connect_wallet_button" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                    Sign In
                                </button>
                                <ul class="dropdown-menu dropdown-menu-end d-none" id="dropdown_menu">
                                    <li><a class="dropdown-item" href="#" id="logout_button">Logout</a></li>
                                </ul>
                            </div>
                        </div>
    
                        <div class="btn-group me-2" role="group" aria-label="theme button">
                            <a href="/#">
                                <i class="bi bi-sun" id="theme_icon" style="font-size: 1.3rem;"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </nav>
    
            <div class="position-absolute top-50 start-50 translate-middle p-3">
                <div class="card">
                    <div class="card-body">
                        <h3 class="card-title text-center">test form</h3>
    
                        <form class="needs-validation" id="form" action="/form" method="post">
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
    
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
    
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
    
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
    
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
    
                            <div class="mb-3">
                                <label for="name" class="form-label">test</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
    
                            <div class="mb-3">
                                <div class="form-check">
                                    <input class="form-check-input" type="checkbox" id="test" value="False" name="test" required>
                                    <label class="form-check-label" for="test">
                                        ???
                                    </label>
                                </div>
                            </div>
            
                            <div class="d-none" id="form_button_group">
                                <button type="button" class="btn btn-secondary" id="clear_button">Clear</button>
                                <button type="submit" class="btn btn-primary" id="submit_button">Submit</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
    
    
    
            <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
            <script type="text/javascript" src="{{ url_for('static', filename='js/dashboard.js') }}"></script>
            <script type="application/javascript" src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"></script>
        </body>
    </html>
    Login or Signup to reply.
  2. The main issue here is that your test form "div" is positioned with absolute causing it to be removed from the normal document flow. As a result, the top position is recalculated according to it’s top: 50% !important rule, when the screen height is smaller or larger, leading to an overlay with the navbar or leaving lots of white space between the two elements.

    To address this, I suggest removing the position rule and specifying a width for the test form "div" (I’m using .container here, you can change it to whatever fits your design). Additionally, add some margin for the navbar:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>test</title>
    
        <link
          href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
          rel="stylesheet"
          integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD"
          crossorigin="anonymous"
        />
        <link
          rel="stylesheet"
          href="{{ url_for('static', filename='css/dashboard.css') }}"
        />
        <link
          rel="stylesheet"
          href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"
        />
      </head>
      <body>
        <nav class="navbar mb-4 bg-body-tertiary">
          <div class="container-fluid">
            <a class="navbar-brand" href="#">
              <img src={{url_for('static', filename='/images/logo.png')}} id="logo"
              alt="Logo" width="50" height="50" class="d-inline-block
              align-text-top" style="border-radius: 5px;">
            </a>
    
            <div
              class="btn-toolbar align-items-center justify-content-center"
              role="toolbar"
              aria-label="Toolbar with button groups"
            >
              <div class="btn-group me-2" role="group" aria-label="sign in">
                <div class="dropdown">
                  <!-- dropdown-toggle -->
                  <button
                    class="btn btn-primary"
                    id="connect_wallet_button"
                    type="button"
                    data-bs-toggle="dropdown"
                    aria-expanded="false"
                  >
                    Sign In
                  </button>
                  <ul
                    class="dropdown-menu dropdown-menu-end d-none"
                    id="dropdown_menu"
                  >
                    <li>
                      <a class="dropdown-item" href="#" id="logout_button"
                        >Logout</a
                      >
                    </li>
                  </ul>
                </div>
              </div>
    
              <div class="btn-group me-2" role="group" aria-label="theme button">
                <a href="/#">
                  <i
                    class="bi bi-sun"
                    id="theme_icon"
                    style="font-size: 1.3rem"
                  ></i>
                </a>
              </div>
            </div>
          </div>
        </nav>
    
        <div class="container">
          <div class="card">
            <div class="card-body">
              <h3 class="card-title text-center">test form</h3>
    
              <form class="needs-validation" id="form" action="/form" method="post">
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
    
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
    
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
    
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
    
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
    
                <div class="mb-3">
                  <label for="name" class="form-label">test</label>
                  <input
                    type="text"
                    class="form-control"
                    id="name"
                    name="name"
                    required
                  />
                </div>
    
                <div class="mb-3">
                  <div class="form-check">
                    <input
                      class="form-check-input"
                      type="checkbox"
                      id="test"
                      value="False"
                      name="test"
                      required
                    />
                    <label class="form-check-label" for="test"> ??? </label>
                  </div>
                </div>
    
                <div class="d-none" id="form_button_group">
                  <button type="button" class="btn btn-secondary" id="clear_button">
                    Clear
                  </button>
                  <button type="submit" class="btn btn-primary" id="submit_button">
                    Submit
                  </button>
                </div>
              </form>
            </div>
          </div>
        </div>
    
        <script
          src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
          integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN"
          crossorigin="anonymous"
        ></script>
        <script
          type="text/javascript"
          src="{{ url_for('static', filename='js/dashboard.js') }}"
        ></script>
        <script
          type="application/javascript"
          src="https://cdn.ethers.io/lib/ethers-5.2.umd.min.js"
        ></script>
      </body>
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search