2013-06-29 36 views
0

是否可以在CSS中聲明整個Google地圖?我的意思是這樣的。
HTML在CSS中指定Google地圖iframe

<iframe id="map"></iframe> 

CSS

#map { 
    width: 300px; 
    height: 300px; 
    frameborder: 0; 
    scrolling: no; 
    marginheight: 0; 
    marginwidth: 0; 
    src: url("https://maps.google.cz/?#####"); 
} 

感謝您的任何幫助。 :)

+0

我想不出有辦法做到這一點。我可以問你爲什麼要這麼做嗎?你可以非常容易地使用javascript設置iframe的src –

+0

當代碼在CSS中而不是在該元素中指定時,代碼變得更清晰。我只需更改CSS即可在所有網站上更改地圖。 – Kyrbi

回答

3

我並不是說這是一個好主意,但是您可以使用iframe中未使用的CSS值之一來完成此操作。

你還是會有一些javascript啓動代碼用正確的值代替src,但是如果你只是添加了那麼一點點,你就可以用css值控制你的iframes src。

CSS

#map1 
{ 
    content: "http://site1.com"; 
} 
#map2 
{ 
    content: "http://site2.com"; 
} 

的Javascript

$(document).ready(function() { 
    //loop through all iframes, and replace the src with the css value of content 
    $("iframe").each(function() { 
     var url = $(this).css("content"); 
     //url comes with the quotes around them, so strip them off 
     url = url.substr(1, url.length -2); 
     $(this).attr("src", url);  
    }); 
}); 

這裏有一個模擬了一下我談論的。 http://jsfiddle.net/mLtWL/

0

既然你不想在你的地圖中的任何類型的功能,你只是想圖像基本上,你可以使用靜態地圖(圖像)。只需通過在url中傳遞正確的參數來構建想要的圖像,然後將其放入css中即可。 Check here for more

0

不,你不能以任何簡單的方式做到這一點。 CSS僅用於控制外觀,iframe的來源不是樣式。

您可能可以使用javascript解析它(即解析樣式並設置源代碼的方式),但是您將以非專門設計的方式使用CSS。

相關問題