简体   繁体   English

Google地图和高度100%的问题?

[英]Issues with Google Map and 100% height?

I'm having an issue getting the height to adjust so that the map will actually appear - I know that I have to set the html and body height to 100% (which I did) and the parent div to 100% (hence the .info div having 100% height) but for some reason it's still not rendering the map properly - the width works fine, but the height doesn't. 我在调整高度以使地图实际显示时遇到问题-我知道我必须将html和body高度设置为100%(我这样做了),并将父div设置为100%(因此设置为)。 info div的高度为100%),但由于某种原因,它仍无法正确渲染地图-宽度可以正常工作,但高度不能正常工作。

I've included a jsfiddle to demonstrate what I mean. 我提供了一个jsfiddle来演示我的意思。

These are the styles I have so far (not including the javascript) 这些是我到目前为止的样式(不包括javascript)

Address & Phone 地址和电话

 <div class="mapWrapper"> <div id="map-canvas"></div> </div> </div> 
html, body {
    width: 100%;
    height: 100%;
}
}
.mapWrapper {
    width: 100%;
    height: 100%;
    margin-bottom: 5%;
    margin-left: 3%;
    padding: 0;
}
#map-canvas {
    width: 65%;
    height: 65%;
    min-height: 65%;
    padding: 0;
    margin: 0;
    border: 3px solid #355868;
}
.info {
    width: 100%;
    height: 100%;
    float: left;
    padding-left: 30px;
}

Actually you've a syntax error in your CSS selector: }.mapWrapper { ... } Remove the first closing curly brace before the .mapWrapper class, And it would work. 实际上,您在CSS选择器中遇到语法错误: }.mapWrapper { ... }删除.mapWrapper类之前的第一个.mapWrapper花括号,然后它将起作用。

So the CSS engine ignores the .mapWrapper { ... } rules and .mapWrapper element (which is the parent of .map-canvas ) , wont't have an explicit height value. 因此,CSS引擎会忽略.mapWrapper { ... }规则和.mapWrapper元素.map-canvas的父元素 ,而没有明确的height值。

Hence, according to spec MDN , for the height property: 因此,根据规范MDN ,对于height属性:

The percentage is calculated with respect to the height of the generated box's containing block. 相对于生成的盒子的包含块的height计算percentage If the height of the containing block is not specified explicitly (ie, it depends on content height), and this element is not absolutely positioned, the value computes to auto . 如果未明确指定包含块的height (即,它取决于内容的高度),并且此元素不是绝对定位的,则该值将计算为auto A percentage height on the root element is relative to the initial containing block. 根元素上的百分比高度是相对于初始包含块的高度。

UPDATED FIDDLE . 更新的内容

For anyone else wondering - using em's over percentages did in fact allow the height to properly adjust. 对于其他任何人都想知道的-使用em的超出百分比实际上确实可以使高度正确调整。 Not entirely sure if that requires you to set the height of parent elements, but all I did was change 100% to an em value, and it worked. 不能完全确定是否需要您设置父元素的高度,但是我所做的只是将100%更改为em值,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM