javascript - 如何更改 Google Places 自动完成的字体大小和字体系列?

标签 javascript html css google-maps-api-3 google-places-api

我目前正尝试在 Javascript API 中调整 Google Places Autocomplete 的 CSS 属性。在这个链接here我可以看到 CSS 类已由 Google 列出。

Autocomplete Font

我尝试直接在 HTML 文件中编辑 CSS:

<style>
    .pac-item-query { font-size: 12px; }
    .pac-item { font-size: 12px; }
    .pac-item-container { font-size: 12px; }
    .pac-item-matched { font-size: 12px; }
</style>

虽然这似乎不起作用。我查看了其他 StackOverflow 帖子,但无法找到有效的解决方案。

这是 HTML 的样子:

<body id="page-top" class="index" onload="initialize()">
<!-- Header -->
<header>
    <div class="container">
        <div class="intro-text">
            <a href="index.html">
                <div class="intro-lead-in">
                    <h3></h3></div>
            </a>
            <div class="form-group">
                <form method="link" action="results.html">
                    <table>
                        <col width="1000">
                        <col width="500">
                        <tr>
                            <div class="col-sm-11">
                                <td colspan="2">
                                    <h3 style="border-bottom: 2px solid white;"> Tell us about your move! </h3><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4>Please enter your pick up address</h4><br>
                                </td>
                                <td>
                                    <input id="start" type="text" class="form-control" placeholder="85 Madeup Street, City, Zip Code, State" name="start"><img src="img/powered-by-google-on-non-white.png"/><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4>Please enter your drop off address</h4><br>
                                </td>
                                <td>
                                    <input id="destination" type="text" class="form-control" placeholder="64 Madeup Street, City, Zip Code, State" name="dest"><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4>Which type of vehicle will you need?</h4><br>
                                </td>
                                <td>
                                    <select id="mode" class="form-control" name="mode">>
                                        <option value="#" selected>Type of Vehicle</option>
                                        <option value="VAN">Van</option>
                                        <option value="SUV">SUV</option>
                                        <option value="TRUCK">Pick Up Truck</option>
                                        <option value="CAR">Car</option>
                                    </select><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td colspan="2">
                                    <h3 style="border-bottom: 2px solid white;"> Enter Contact Information </h3><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4>Please let us know your name</h4><br>
                                </td>
                                <td>
                                    <input id="name" type="text" class="form-control" placeholder=" e.g. John Johnson" name="name"><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4>Please enter your phone number. We will notify you when your driver is on their way</h4> <br>
                                </td>
                                <td>
                                    <input id="phone" type="tel" class="form-control" name="phone" placeholder=" e.g. 781222777"><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4>Please provide your email</h4><br>
                                </td>
                                <td>
                                    <input id="email" type="email" class="form-control" name="email" placeholder=" e.g. example@example.com"><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <div class="col-sm-11">
                                <td>
                                    <h4> Could you please describe the items you are moving and the quantity?</h4><br>
                                </td>
                                <td colspan="2">
                                    <textarea id="description" class="form-control" name="description" placeholder=" e.g. 1 large couch, 2 small lamps, and a fruit bowl."></textarea><br>
                                </td>
                            </div>
                        </tr>
                        <tr>
                            <td>
                                <h4></h4><br>
                            </td>
                            <td>
                                <select id="help" class="form-control" placeholder="">
                                    <option value="Yes" selected>Yes Please!</option>
                                    <option value="No" selected>No Thank You</option>
                                </select><br>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <input type="submit" class="page-scroll btn btn-xl" color="black" id="submit" onclick="saveData()">
                            </td>
                        </tr>
                    </table>
                </form>

            </div>
        </div>
    </div>
</header>

还有 Javascript

// USES THE GOOGLE PLACES LIBRARY
// ==============================
// This example displays an address form, using the autocomplete feature
// of the Google Places API to help users fill in the information.

var placeSearch, autoCompleteOrigin, autoCompleteDest;
var componentForm = {
  street_number: 'short_name',
  route: 'long_name',
  locality: 'long_name',
  administrative_area_level_1: 'short_name',
  country: 'long_name',
  postal_code: 'short_name'
};

function initialize() {
  // Create the autocomplete object, restricting the search
  // to geographical location types.
  autoCompleteOrigin = new google.maps.places.Autocomplete(
      /** @type {HTMLInputElement} */(document.getElementById('start')),
      { types: ['geocode'] });
  autoCompleteDest = new google.maps.places.Autocomplete(
      /** @type {HTMLInputElement} */(document.getElementById('destination')),
      { types: ['geocode'] });
  // When the user selects an address from the dropdown,
  // populate the address fields in the form.
  google.maps.event.addListener(autoCompleteOrigin, 'place_changed', function() {
    fillInAddress();
  });
  google.maps.event.addListener(autoCompleteDest, 'place_changed', function() {
    fillInAddress();
  });
}

function fillInAddress() {
  // Get the place details from the autocomplete object.
  var place = autocomplete.getPlace();

  for (var component in componentForm) {
    document.getElementById(component).value = '';
    document.getElementById(component).disabled = false;
  }

  // Get each component of the address from the place details
  // and fill the corresponding field on the form.
  for (var i = 0; i < place.address_components.length; i++) {
    var addressType = place.address_components[i].types[0];
    if (componentForm[addressType]) {
      var val = place.address_components[i][componentForm[addressType]];
      document.getElementById(addressType).value = val;
    }
  }
}

// Bias the autocomplete object to the user's geographical location,
// as supplied by the browser's 'navigator.geolocation' object.
function geolocate() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      var geolocation = new google.maps.LatLng(
          position.coords.latitude, position.coords.longitude);
      var circle = new google.maps.Circle({
        center: geolocation,
        radius: position.coords.accuracy
      });
      autocomplete.setBounds(circle.getBounds());
    });
  }
}

最佳答案

已修复!我不得不进入 bootstrap css 并更改 span { font-size: 50px; }span { font-size: 12px;

关于javascript - 如何更改 Google Places 自动完成的字体大小和字体系列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30376008/

相关文章:

javascript - 如何知道用户何时滚动过 <div>?

javascript - 如何获取文本区域值的字节大小

javascript - 给定一个整数数组,找到数组中第二大和第二小的整数

javascript - Jquery jquery.sumoselect

非空,数字和字母的javascript验证

html - 我应该为移动 Web 应用程序使用什么文档类型?

javascript - Dropzone.js - 在排队文件长度 > 0 上显示按钮

javascript - 为什么我的图像按钮没有打开它应该打开的链接?

css - 使用@font-face 会减慢加载时间。我可以强制客户端缓存字体吗?

html - 可点击区域与 div 的显示不对齐?