Javascript 如何在div的背景中加载谷歌地图?
我是CSS新手,我想在div背景中加载GoogleMap。我当前的代码写在下面: HTMLJavascript 如何在div的背景中加载谷歌地图?,javascript,html,css,Javascript,Html,Css,我是CSS新手,我想在div背景中加载GoogleMap。我当前的代码写在下面: HTML <div class="map"></div> <script src="http://maps.googleapis.com/maps/api/js?key=mykey&sensor=false"></script> 您可以将Google mapsdiv设置为背景,然后将所有其他元素放置在Google maps div上 通过增加z-index并
<div class="map"></div>
<script src="http://maps.googleapis.com/maps/api/js?key=mykey&sensor=false"></script>
您可以将Google maps
div
设置为背景,然后将所有其他元素放置在Google maps div上
通过增加
z-index
并将这些元素放置为绝对位置。您可以将Google mapsdiv
设置为背景,然后将所有其他元素放置在Google maps div上
通过增加z-index
并将这些元素放置为绝对位置。CSS中存在一些问题:
background-image:url(https://maps.google.co.in/maps?q=new+Delhi&hl=en&sll=28.572047,77.069178&sspn=0.02348,0.039482&hnear=Delhi&t=m&z=10)
将其替换为:
background-image:url('https://maps.google.co.in/maps?q=new+Delhi&hl=en&sll=28.572047,77.069178&sspn=0.02348,0.039482&hnear=Delhi&t=m&z=10');
请注意url周围的单引号(”
),以及末尾的分号(;
)。
添加引号是因为背景图像的参数应为字符串。CSS中存在一些问题:
background-image:url(https://maps.google.co.in/maps?q=new+Delhi&hl=en&sll=28.572047,77.069178&sspn=0.02348,0.039482&hnear=Delhi&t=m&z=10)
html, body {
height:100%;
}
#map-container {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 0;
}
#map
{
width: 100%;
height: 100%;
background-image:url(https://maps.google.co.in/maps? q=new+Delhi&hl=en&sll=28.572047,77.069178&sspn=0.02348,0.039482&hnear=Delhi&t=m&z=10)
background:white;
width:1000px;
height:500px;
margin-left:20
}
#content
{
position: absolute;
z-index: 1;
top:0;
left:0;
padding:20px;
background-color: rgba(255,255,255,0.5);
}
将其替换为:
background-image:url('https://maps.google.co.in/maps?q=new+Delhi&hl=en&sll=28.572047,77.069178&sspn=0.02348,0.039482&hnear=Delhi&t=m&z=10');
请注意url周围的单引号(”
),以及末尾的分号(;
)。
添加引号是因为背景图像的参数应该是字符串。我会使用谷歌的静态地图作为背景(没有任何js)
html, body {
height:100%;
}
#map-container {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 0;
}
#map
{
width: 100%;
height: 100%;
background-image:url(https://maps.google.co.in/maps? q=new+Delhi&hl=en&sll=28.572047,77.069178&sspn=0.02348,0.039482&hnear=Delhi&t=m&z=10)
background:white;
width:1000px;
height:500px;
margin-left:20
}
#content
{
position: absolute;
z-index: 1;
top:0;
left:0;
padding:20px;
background-color: rgba(255,255,255,0.5);
}
我做了一些简单的示例(仅在主体上使用css):
编辑:具有固定宽度/高度和新德里的示例
url中的p.S.大小应与div宽度/高度成比例。对于非商业应用,最大图像大小为640x640,但其1280px 1280px,因此您可以对其进行更多拉伸。我将使用谷歌的静态地图作为背景(没有任何js)
我做了一些简单的示例(仅在主体上使用css):
编辑:具有固定宽度/高度和新德里的示例
url中的p.S.大小应与div宽度/高度成比例。对于非业务,最大图像大小为640x640,但其1280px 1280px,因此您可以对其进行更大的拉伸。我搜索了很多次检查我的代码表,您没有-我搜索了很多次检查我的代码表,您没有-因为参数应该是字符串^^[…]因为参数应该是一个字符串^^对于显示标记和其他内容,您必须在google静态地图api上读取要传递的确切参数。对于显示标记和其他内容,您必须在google静态地图api上读取要传递的确切参数。