【发布时间】:2015-08-03 06:07:29
【问题描述】:
我目前正在尝试在 Javascript API 中调整 Google Places Autocomplete 的 CSS 属性。在此链接here 中,我可以看到 CSS 类是由 Google 列出的。
我尝试直接在 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());
});
}
}
【问题讨论】:
-
当我把它变成一个 jsfiddle 时,你的代码似乎运行良好:jsfiddle.net/xiondark2008/4m4f1pq9。我发现的唯一可能的“问题”不在您链接的 Google 文档中:“注意:下面描述的 CSS 类是 Google Maps JavaScript API 实验版本的一部分。不保证对实验版本所做的更改是功能稳定。有关详细信息,请参阅版本控制。那么您使用的是实验性构建版本吗?
-
嗯...有趣。这可能是我使用的默认 CSS 会影响字体,但我不知道这怎么可能,因为我没有类似于 API 自动完成属性的 CSS 属性。我确定我没有使用实验版本。
-
在 JSFiddle 中,我正在使用实验版本,因为文档说明说它是必需的。但是,我只是使用最新版本(“/js?v=3&....”)进行了尝试,css 类仍然有效。如果这有帮助,看起来 Google 在 header 元素之外创建了一个带有“pac-container”类的 div。自动完成菜单的结果是 div 和 span。
-
@XionDark 好的,所以我使用了我拥有的 CSS 文件,发现我的引导 CSS 文件正在影响自动完成,但究竟是什么问题?引导程序中的什么影响了文本? Bootstrap CSS Gist不知道怎么回事
-
我注意到您链接的 css 将 span 元素的字体大小设置为 50px(这似乎与您的屏幕截图相匹配)。包含 Bootstrap 库后是否定义了 CSS?
标签: javascript html css google-maps-api-3 google-places-api