为什么Javascript按钮上有额外的空间?

时间:2015-08-12 03:25:19

标签: javascript button imagebutton

我一直在试图解决这个问题,但是经过4个小时的挖掘和盯着我的代码后我就放弃了。

代码:

<!DOCTYPE html>
<html>
<head>
<title>Listening to DOM events</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html,body,#map-canvas {
    height: 100%;
    width: 100%;    
    margin: 0;
    padding: 0;
}

.controls {
    margin-top: 0px;
    border: 1px solid transparent;
    border-radius: 2px 0 0 2px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    height: 32px;
    outline: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#pac-input {
    background-color: #fff;
    font-family: Roboto;
    font-size: 15px;
    font-weight: 300;
    margin-left: 5px;
    padding: 0 11px 0 13px;
    text-overflow: ellipsis;
    width: 240px;
}

#pac-input:focus {
    border-color: #4d90fe;
}

.pac-container {
    font-family: Roboto;
}

#type-selector {
    color: #fff;
    background-color: #4d90fe;
    padding: 5px 11px 0px 11px;
}

#type-selector label {
    font-family: Roboto;
    font-size: 13px;
    font-weight: 300;
}
</style>

<title>Places search box</title>


<script 

    src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>

<script>

var map;
var marker;
var latLng;

function initialize() {

      var myLatlng = new google.maps.LatLng(xxxx, -xxxxx);
      var mapOptions = {
      zoom: 10,
      mapTypeControl: false,
      navigationControl: false,
      scrollwheel: false,
      scaleControl: true,
      center: myLatlng
  };

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

}  //End of OnStart


google.maps.event.addDomListener(window, 'load', initialize);


</script>

    <style>
      #panel {
        position: absolute;
        top: 0px;
        left: 50%;
        margin-left: -180px;
        width: 240px;
        z-index: 5;
        background-color: #00ffec;
        padding: 5px;
        border: 1px solid #999;
      }
      #latlng {
        width: 240px;
      }

      #target {
        width: 240px;
      }

    </style>

  </head>
  <body>
    <div> 
      <input id="pac-input" class="controls" type="text" placeholder=""> 
      <input type="button" value="Clear" style="Float:right" style="width:60px; height:40px"
                                                                                onclick="Clear_SearchText()">    
    </div>  
    <div id="map-canvas"></div>
  </body>
</html>

有人可以帮助我理解为什么有一个额外的空间占据我的布局空间????

非常感谢

编辑:重新上传更好的图片。

enter image description here

1 个答案:

答案 0 :(得分:0)

文字div和按钮input的容器input将占据该位置。 最简单的方法是将按钮inputdiv高度设置为匹配。使按钮匹配的示例:

将ID添加到按钮以引用它:

<input id="clearbutton" type="button" value="Clear" style="Float:right" style="width:60px; height:40px" onclick="Clear_SearchText()">

在css中设置高度:

<style>
#clearbutton {
    height: 32px;
}
</style>

示例:http://jsfiddle.net/ddan/pqdtgmdp/1/

修改

所以基于你的完整例子:

<!DOCTYPE html>
<html>
<head>
<title>Listening to DOM events</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html,body,#map-canvas {
    height: 100%;
    width: 100%;    
    margin: 0;
    padding: 0;
}

.controls {
    margin-top: 0px;
    border: 1px solid transparent;
    border-radius: 2px 0 0 2px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    height: 32px;
    outline: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

#pac-input {
    background-color: #fff;
    font-family: Roboto;
    font-size: 15px;
    font-weight: 300;
    margin-left: 5px;
    padding: 0 11px 0 13px;
    text-overflow: ellipsis;
    width: 240px;
}

#pac-input:focus {
    border-color: #4d90fe;
}

.pac-container {
    font-family: Roboto;
}

#type-selector {
    color: #fff;
    background-color: #4d90fe;
    padding: 5px 11px 0px 11px;
}

#type-selector label {
    font-family: Roboto;
    font-size: 13px;
    font-weight: 300;
}
</style>

<title>Places search box</title>


<script 

    src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places"></script>

<script>

var map;
var marker;
var latLng;

function initialize() {

      var myLatlng = new google.maps.LatLng(xxxx, -xxxxx);
      var mapOptions = {
      zoom: 10,
      mapTypeControl: false,
      navigationControl: false,
      scrollwheel: false,
      scaleControl: true,
      center: myLatlng
  };

map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

}  //End of OnStart


google.maps.event.addDomListener(window, 'load', initialize);


</script>

    <style>
      #panel {
        position: absolute;
        top: 0px;
        left: 50%;
        margin-left: -180px;
        width: 240px;
        z-index: 5;
        background-color: #00ffec;
        padding: 5px;
        border: 1px solid #999;
      }
      #latlng {
        width: 240px;
      }

      #target {
        width: 240px;
      }

      #clearbutton, #pac-input{
        height: 32px;
      }
    </style>
  </head>
  <body>
    <div> 
      <input id="pac-input" class="controls" type="text" placeholder=""> 
      <input id="clearbutton" type="button" value="Clear" style="Float:right" style="width:60px; height:40px"
                                                                                onclick="Clear_SearchText()">    
    </div>  
    <div id="map-canvas"></div>
  </body>
</html>