[FIXED] html navigation bar with mapbox

Issue

I have a flask app where with a home screen, world map, and an about page all extended in Flask with a NAV bar, looks like this:

enter image description here

With Jinja it seems like I can make use of templates to create a nav bar with this below from base.htlm (not shown):

<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
    {% extends 'base.html' %}

    {% block content %}

    {% endblock %}
</body>
</html>

What I cant figure out is when creating a map in mapbox and using the html,css,js boiler plate code is how can I extend my nav bar with Jinja templating?

<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta charset='utf-8' />
    <title>asdf</title>
    <meta name='viewport' content='width=device-width, initial-scale=1' />
    <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v2.9.2/mapbox-gl.js'></script>
    <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v2.9.2/mapbox-gl.css' rel='stylesheet' />
    <style>
      body { 
        margin: 0; 
        padding: 0; 
      }
      #map { 
        position: absolute; 
        top: 0; 
        bottom: 0; 
        width: 100%; 
      }
    </style>
  </head>
    <body>
      {% extends 'base.html' %}

      {% block content %}
        <div div id='map'></div>
            <script>

              mapboxgl.accessToken = 'asfdadsfadfs'; 
              const map = new mapboxgl.Map({
                container: 'map',
                style: 'mapbox://asdf', 
                center: [-87.661557, 41.893748],
                zoom: 3
              });

            </script>
        {% endblock %}
    </body>
</html>

This will render my nav bar template comes through half cut off:

enter image description here

Any tips greatly appreciated not alot of wisdom here. For what its worth this is base.html

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

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KyZXEAg3QhqLMpG8r+8fhAXLRk2vvoC2f3B09zVXn8CA5QIVfZOJ3BCsw2P0p/We" crossorigin="anonymous">

    <title>{% block title %} {% endblock %} - BensApp</title>
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container-fluid">
        <a class="navbar-brand" href="{{ url_for('hello') }}">Home</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav">
            <li class="nav-item">
              <a class="nav-link" href="{{ url_for('heatmap') }}">World Heat Map</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="{{ url_for('about') }}">About</a>
            </li>
        </ul>
        </div>
    </div>
    </nav>
    <div class="container">
        {% block content %} {% endblock %}
    </div>

    <!-- Optional JavaScript -->

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-U1DAWAznBHeqEIlVSCgzq+c9gqGAJn5c/t99JyeKa9xxaYpSvHU5awsuZVVFIhvj" crossorigin="anonymous"></script>

  </body>
</html>

Solution

You might use the css min-width and max-width options for the box.

This controls how big the image or the navbar is. According to quick search, Flask does support CSS, only in a specific folder called static. This means other stuff won’t overflow the container; it instead makes a side-by-side look.

Answered By – stech

Answer Checked By – Robin (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published