【问题标题】:react-google-maps: How can I dynamically style the Google container (.pac-container) of multiple StandaloneSearchBox components?react-google-maps:如何动态设置多个 StandaloneSearchBox 组件的 Google 容器 (.pac-container) 样式?
【发布时间】:2019-01-08 19:06:18
【问题描述】:

使用 react-google-maps 创建的 Google 地方信息搜索框的容器具有名为 .pac-container 的类。现在,我在一页上有多个,我想给它们设置不同的样式。例如,一个应该向上下降,另一个应该向下。

我怎样才能做到这一点?我不能传递类名...

【问题讨论】:

    标签: reactjs google-maps google-places-api react-google-maps


    【解决方案1】:

    您可以使用父包装器来包装 StandAloneSearchBox。

    <div className="ancestor1"><StandAloneSearchBox></div>
    <div className="ancestor2"><StandAloneSearchBox></div>
    

    .ancestor1 .pac-container
    .ancestor2 .pac-container
    

    也许您需要输入StandAloneSearchBox,因为有时谷歌地图会忽略父 div。如果问题仍然存在,请告诉我。

    【讨论】:

    • 我还没有尝试过,但这听起来是正确的做法
    • 抱歉,这行得通吗?我正在尝试,但它对我不起作用:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 2014-01-28
    • 2017-09-20
    • 2021-08-24
    • 2019-06-22
    • 1970-01-01
    相关资源
    最近更新 更多