代码之家  ›  专栏  ›  技术社区  ›  S S

地图显示后不出现按钮

css
  •  0
  • S S  · 技术社区  · 6 年前

    有人能告诉我我做错了什么吗?

    var myloc = new L.LatLng(13.7433242, 100.5421583);
    var map = L.map('map').setView(myloc, 12);
    
    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
      attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
      maxZoom: 18,
      id: 'mapbox.streets',
      accessToken: 'pk.eyJ1Ijoic2FuaW5kcmEiLCJhIjoiY2pqam5qZzZnMHRycTNrbWR3ZGF4Mmd5eSJ9.ZRIVhopMmACa80OQ0yZN3g'
    }).addTo(map);
    .container {
      width: 100%;
    }
    
    #map {
      height: 80%;
      width: 100%;
      top: 0;
      left: 0;
      position: absolute;
      clear: both;
    }
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <body>
      <div class="container">
        <div class="row">
          <div id="map"></div>
        </div>
    
        <div class="row">
          <input type="button" id="btn-first" class="btn-a" value="First">
          <input type="button" id="btn-second" class="btn-a" value="Second">
        </div>
    
      </div>
    </body>
    4 回复  |  直到 6 年前
        1
  •  1
  •   Viira    6 年前

    干得好! 这也许对你有帮助。

    我在按钮上加了一个类 position:absolute; bottom:0; 把他们打倒了。希望对你有帮助。

    var myloc = new L.LatLng(13.7433242, 100.5421583);
    var map = L.map('map').setView(myloc, 12);
    
    L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
      attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
      maxZoom: 18,
      id: 'mapbox.streets',
      accessToken: 'pk.eyJ1Ijoic2FuaW5kcmEiLCJhIjoiY2pqam5qZzZnMHRycTNrbWR3ZGF4Mmd5eSJ9.ZRIVhopMmACa80OQ0yZN3g'
    }).addTo(map);
    .container {
      width: 100%;
    }
    
    #map {
      height: 80%;
      width: 100%;
      top: 0;
      left: 0;
      position: absolute;
      clear: both;
    }
     /*this is what I've added*/
    .btns{bottom:0; position:absolute;}
     /*this is what I've added*/ 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
    <body>
      <div class="container">
        <div class="row">
          <div id="map"></div>
        </div>
    
        <div class="row btns">
          <input type="button" id="btn-first" class="btn-a" value="First">
          <input type="button" id="btn-second" class="btn-a" value="Second">
        </div>
    
      </div>
    </body>
        2
  •  1
  •   ThS    6 年前

    .row:nth-child(2) {
        margin-top: 80%;
    }
    
        3
  •  1
  •   VSM    6 年前
    #map {
    height: 200px;
    width: 100%;
    position: relative;
    clear: both;
    }
    

    这很管用。。

        4
  •  -1
  •   Anji    6 年前

    根据您的评论更新了代码“是的,我已经尝试添加z-index。。但是这个按钮出现在地图上。我要在地图下面给他们看”

    jsfiddle.net/1bwmyhd/4

    HTML格式:-

    <div class="container">
    <div class="row map-block">
      <div id="map"></div>
    </div>
    
    <div class="row">
      <input type="button" id="btn-first" class="btn-a" value="First">
      <input type="button" id="btn-second" class="btn-a" value="Second">
    </div>
    

    为映射父行添加了额外的类。

    CSS:-

    .map-block{
       position:relative;
       min-height:200px;
    }
    
    #map {
      height: 100%;
      width: 100%;
      top: 0;
      left: 0;
      position: absolute;
      clear: both;
      z-index: -1;
    }