如何在传单地图上放置按钮

vai*_*hah 13 html javascript css leaflet

我在我的应用程序中使用传单映射并使用引导程序来响应.我在地图上有一些按钮.它看起来像这样.

在此输入图像描述

但我想像这样重叠地图上的按钮

在此输入图像描述

这是我的HTML

        <div class="span9" style="height:100%">
        <div id="map"></div>
        <div style="padding-left: 10px;padding-right: 10px">
            <input type="button" id="Btn1" value="Btn1" onclick="" class="btnStyle span3" />
            <input type="button" id="Btn2" value="Btn2" onclick="SaveRoutes()" class="btnStyle span3" /> 
            <input type="button" id="Btn3" value="Btn3" onclick="editRoutes()" class="btnStyle span3" />
            <span id="studentsCount" class="lblStyle span3"> Ikke rutesat: </span>
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

我的地图css

html, body, #map, .row-fluid{
 height: 100%;
 }

 #map {
width: 100%;
}


.btnStyle {
background-color: #4D90FE; 
background-image: -moz-linear-gradient(center top , #4D90FE, #4787ED); 
border: 1px solid #3079ED; 
color: #FFFFFF;
 padding: 4px;
 margin-top: 4px;
 margin-bottom: 4px;
 width:100%
}

.lblStyle {
color: red;
 padding: 4px;
 margin-top: 4px;
 margin-bottom: 4px;
width: 100%;
font-weight: bold;
}
Run Code Online (Sandbox Code Playgroud)

Nin*_*ari 13

我希望我理解你,这有帮助.这是小提琴:http://jsfiddle.net/g3JrG/4/

HTML:

<div class="span9" style="height:100%">
    <div id="map-wrapper">
        <div id="map"></div>
        <div id="button-wrapper">
            <input type="button" id="Btn1" value="Btn1" class="btnStyle span3" />
            <input type="button" id="Btn2" value="Btn2" class="btnStyle span3" /> 
            <input type="button" id="Btn3" value="Btn3" class="btnStyle span3" />
         </div> 
    </div>
    <span id="studentsCount" class="lblStyle span3"> Ikke rutesat: </span>
</div>
Run Code Online (Sandbox Code Playgroud)

CSS:

#map-wrapper {
    width: 100%;
    height: 500px;
    position: relative;
    border: 1px solid black;
}

#map {
    width: 100%;
    height: 100%;
    background-color: green;
}

#button-wrapper {
    position: absolute;
    bottom: 10px;
    width: 100%;
    border: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)

TJL

  • 从按钮`position:relative;添加到容器中 z-index:9999;` (2认同)

小智 12

Leaflet.js提供以下类:

leaflet-bottom
leaflet-top
leaflet-left
leaflet-right
Run Code Online (Sandbox Code Playgroud)

通用HTML示例:

    <div id="divmap"> <!--leaflet map wrapper div -->
        <div id="map" > <!--leaflet map div -->
            <div class="leaflet-bottom leaflet-left">
                <div id="marker-legend">  <!-- here the legend -->
                </div>
            </div>          
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

将以前的HTML与您的特定问题相匹配:

 <div class="span9" style="height:100%">
    <div id="map">
        <div class="leaflet-bottom leaflet-left">
            <input type="button" id="Btn1" value="Btn1" onclick="" class="btnStyle span3" />
            <input type="button" id="Btn2" value="Btn2" onclick="SaveRoutes()" class="btnStyle span3 leaflet-control" /> 
            <input type="button" id="Btn3" value="Btn3" onclick="editRoutes()" class="btnStyle span3 leaflet-control" />
            <span id="studentsCount" class="lblStyle span3 leaflet-control"> Ikke rutesat: </span>
        </div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

  • 风格很好.但是我不能再单击该按钮了.知道为什么吗? (6认同)
  • @nha @Magda问题是`leaflet-bottom`,`-top`,`-right`,`-left`具有`pointer-events:none;`属性,这意味着该元素不能成为目标。鼠标事件了。您可以通过在按钮上添加`pointer-events:auto;`来覆盖它。 (2认同)