【问题标题】:CSS in Google Earth pluginGoogle 地球插件中的 CSS
【发布时间】:2009-07-29 18:46:19
【问题描述】:

只是想知道是否可以通过外部/链接的.css 文件而不是内联样式来设置弹出气球的样式?

【问题讨论】:

    标签: css kml google-earth google-earth-plugin


    【解决方案1】:

    我通常做的是为我的地标气球创建一个 BalloonStyle,其中包含一个包装器 div 和一个 CSS 类,如 earth-balloon,然后可以直接在包含页面内设置样式。

    例如,KML 如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
      <Document>
        <Style id="foo">
          <BalloonStyle>
            <text><![CDATA[
            <div class="earth-balloon">
              $[description]
            </div>
            ]]></text>
          </BalloonStyle>
        </Style>
        <Placemark>
          <styleUrl>#foo</styleUrl>
          <name>Bar</name>
          <description><![CDATA[
            Some <em>HTML</em> here.
          ]]></description>
          <Point>
            <coordinates>-122,37</coordinates>
          </Point>
        </Placemark>
      </Document>
    </kml>
    

    包含页面本身可能如下所示:

    <html>
    <head>
      <link rel="stylesheet" type="text/css" href="styles.css"/>
      <!-- Earth API stuff goes here -->
    </head>
    <body>
      <div id="map3d"></div>
    </body>
    </html>
    

    然后您的 styles.css 可以通过以下规则为带有 styleUrl = #foo 的地标设置气球样式:

    .earth-balloon {
      font-family: Georgia, serif;
    }
    
    .earth-balloon em {
      color: red;
    }
    

    希望有帮助!

    【讨论】:

      【解决方案2】:

      是的,我过去曾这样做过,这可能非常棘手。您需要使用 firebug 来确定需要获取的选择器,并且在您的 CSS 中,您必须非常具体地覆盖它们,有时您甚至可能必须在规则上使用 !important。

      娜塔莉

      【讨论】:

      • 太好了,我该怎么做,外部文件需要链接到哪里?您也可以指出我的任何示例操作方法。问候。 .k
      • This 是我很久以前研究的东西,它已经改变了一点,但应该给你一个想法,看看 firebug 和 banklocator.css 中的代码
      • 嘿,看起来你不能把 html 放在 cmets 中,只能放在答案中 :) - url 是 recyclenow.com/applications/recyclenow_08/banklocator/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多