gpt4 book ai didi

css - 如何在信息窗口内将 Google StreetView 显示与文本垂直对齐?

转载 作者:行者123 更新时间:2023-11-28 13:25:30 27 4
gpt4 key购买 nike


由于 CSS 的 vertical-align: middle 古怪之处,这是不必要的困难。我明白(虽然违反直觉)如果您想在图像旁边垂直居中放置文本,您必须对图像执行此操作而不是文本...

似乎这种方法只适用于文本位于 span 容器中,图像由 img 标记定义,并且它们都位于 div< 中的情况 容器。

话虽如此,我在 Google map 中有一个信息窗口,其中包含一个位于 Google 街景显示(图像?)左侧的地址(文本)。但是,街景对象不是 img 标记,而是位于 span 容器中。

这是相关代码:

<!DOCTYPE html>
<html>
<head>
<title>address and street-view inside an infowindow</title>

<style type = "text/css">
*
{
margin: 0px;
padding: 0px;
}
html, body
{
height: 100%;
}

#map_canvas
{
min-height: 100%;
}

/* inside infowindow */
#userAddress
{
float: left;
}
#street_canvas
{
float: right;

width: 100px;
height: 100px;

vertical-align: middle;
}
</style>
</head>
<body>

<!-- map here -->
<div id = "map_canvas"></div>

<!-- Google Maps API -->
<script type = "text/javascript" src = "http://maps.googleapis.com/maps/api/js?&amp;sensor=true&amp;v=3.9"></script>

<script type = "text/javascript">

var map;
initialize();

function initialize()
{
var mapOptions =
{
center: new google.maps.LatLng(37.09024, -95.712891), // coordinates for center of the United States
zoom: 4, // smaller number --> zoom out
mapTypeId: google.maps.MapTypeId.TERRAIN // ROADMAP, SATELLITE, TERRAIN, or HYBRID
};

map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

} // end of initialize

var coordinates = new google.maps.LatLng(37.414341, -122.07692159999999);
var address = "1401 North Shoreline Boulevard Mountain View, CA 94043";
setMarker(coordinates, address);

function setMarker(userCoordinates, userAddress)
{
var panorama = null;

// user address map marker created here
var marker = new google.maps.Marker(
{
map: map, // from the global variable
position: userCoordinates
});

// infowindow created here
var windowInfo = "<div>" +
"<span id = 'userAddress'>" + userAddress + "</span>" +
"<span id = 'street_canvas'></span>" +
"</div>";

var infoWindow = new google.maps.InfoWindow(
{
content: windowInfo
});

function setStreetView(infoWindow, userCoordinates)
{
google.maps.event.addListener(infoWindow, "domready", function()
{
if(panorama !== null)
{
panorama.unbind("position");
panorama.setVisible(false);
}

// options for streetview inside map marker
var panoramaOptions =
{
position: userCoordinates,
pov:
{
heading: 45, // northwest in degrees
zoom: 1,
pitch: 1 // 0 degrees is level
},

// removing all map controls
addressControl: false,
clickToGo: false,
enableCloseButton: false,
imageDateControl: false,
linksControl: false,
panControl: false,
scrollwheel: false,
zoomControl: false,

disableDoubleClickZoom: true
};

// initializing streetview and settings to global variable
panorama = new google.maps.StreetViewPanorama(document.getElementById("street_canvas"), panoramaOptions);
panorama.bindTo("position", marker);
panorama.setVisible(true);

});
} // end of setStreetView

setStreetView(infoWindow, userCoordinates);

// event listener for infowindow of map marker, onclick
google.maps.event.addListener(marker, "click", function()
{
infoWindow.open(map, this);
map.panTo(this.position);
});

// event listener for closing infowindow of map marker
google.maps.event.addListener(infoWindow, "closeclick", function()
{
// disable streetview, with the global variable
panorama.unbind("position");
panorama.setVisible(false);
panorama = null;
});
} // end of setMarker
</script>
</body>
</html>

参见 this有关将街景显示放在信息窗口内的引用

最佳答案


因此,这比我想象的要容易得多——必须在文本的 CSS 中设置一个 line-height 属性,等于街景 div 指定的高度。就是这样,文本然后“垂直居中”:

/* inside the infowindow */
#userAddress
{
float: left;

line-height: 100px;
}
#street_canvas
{
float: right;

width: 100px;
height: 100px;
}


在这种情况下不需要 vertical-align: middle

关于css - 如何在信息窗口内将 Google StreetView 显示与文本垂直对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13977286/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com