bootstrap navbar与另一个div

问题描述 投票:0回答:1
<!DOCTYPE html> <html> <head> <title>Title</title> <meta charset="UTF-8"> <!-- Leaflet--> <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" /> <script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script> <!-- Jquery --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <!-- Bootstrap--> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> <style> html, body {height: 100%; margin: 0;} #map { width: 100%; height: 100%; } </style> </head> <body> <!-- Simple Navbar--> <nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item"> <select class="custom-select"> <optgroup label="Menu"> <option selected value="0">Option 0</option> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> </optgroup> </select> </li> </ul> </div> </nav> <!-- Div for my Leaflet map--> <div id='map'></div> <script> myMap = L.map('map') myMap.setView([0,0], 3) BgLayer = L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png') BgLayer.addTo(myMap) </script> </body> </html>

这就是结果的样子:

在此屏幕上抓取时,我们可以看到菜单后面的地图(及其缩放按钮“ +/-”),这意味着地图始于浏览器窗口的最顶部,而不是在Navbar的底部。 enter image description here我怎么能(即利用Bootstrap的容器?)确保Navbar和Map Div不要重叠?

thanks!

您可以使用

display:flex

重组布局以解决重叠问题。
twitter-bootstrap leaflet
1个回答
1
投票
使用一个

d-flex flex-column h-100

容器

使用地图容器适合其余空间并将地图放在内部
  1. flew-grow-1

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.