2012-04-20 35 views
7

我在页面上使用height="100%"width="100%"在全角谷歌地图。我想知道一些css div的东西顶部它。我读到使用负值(例如margin-top: -500px;)可以工作,但他们这样做,但是当我尝试为div的背景分配一种颜色时,它不会在地图上显示它,而是在它下面显示它,我想要什么。有针对这个的解决方法吗? 代码:全宽Google地图和CSS

<iframe width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?hl=en&amp;ie=UTF8&amp;ll=37.0625,-95.677068&amp;spn=56.506174,79.013672&amp;t=m&amp;z=4&amp;output=embed"></iframe> 

<div class="content"> I want this text to be in a div box that has a black background. <br /> </div> 

风格:

.content { 
    margin-top: -500px; 
    width: 390px; 
    background-color: black; 
} 
+0

这上面的DIV是修复[设为谷歌地图集装箱DIV宽度和高度100%](http://stackoverflow.com/a/18147172/782535) – 2013-08-09 13:10:44

回答

12
html, body { 
    width: 100%; 
    height: 100%; 
} 

.map-frame { 
    width: 100%; 
    height: 100%; 
    position: relative; 
} 

.map-content { 
    z-index: 10; 
    position: absolute; 
    top: 50px; 
    left: 50px; 
    width: 390px; 
    background-color: black; 
    color: #FFF; 
} 

http://jsfiddle.net/oswaldoacauan/tx67C/

+0

是的,而负边界语义正确我也建议使用绝对定位。 – 2015-03-22 08:31:18

1

添加到您的CSS。在Chrome浏览器的至少

position:absolute; 
z-index:9999; 
color:#fff; 
0

要风格应该被绝对定位,并给予了积极的z-index,使其显示在地图不低于