div在Firefox中居中显示,但不在IE中 [英] div is displayed centered in Firefox, but not in IE

查看:122
本文介绍了div在Firefox中居中显示,但不在IE中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在 div (用于Google地图)通过将左侧空白空白右侧设置为 auto ,但只适用于Firefox,但不能使用Internet Explorer:

 < html> 
< head>
< style type =text / css>
h1,h2,h3,p {text-align:center; }
#map {width:700;身高:280; margin-left:auto; margin-right:auto; }
< / style>
< script type =text / javascript
src =http://maps.google.com/maps/api/js?sensor=false>
< / script>
< script type =text / javascript>

函数init(){
var latlng = new google.maps.LatLng(-34.397,150.644);
var opts = {
zoom:9,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map),opts);
}

< / script>
< head>
< body onload =init();>
< h3> Map< / h3>
< div id =map>< / div>
< / body>
< / html>

请问有谁知道如何将IE中的 div 居中?
Alex

使用doctype,<!DOCTYPE HTML> 之前触发标准模式。

I'm trying to align a div (used for Google Maps) in page center by setting margin-left and margin-right to auto, but this only works with Firefox, but not with Internet Explorer:

<html>
<head>
<style type="text/css">
    h1,h2,h3,p { text-align: center; }
 #map { width: 700; height: 280; margin-left: auto; margin-right: auto; }
</style>
<script type="text/javascript"
 src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">

function init() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
 var opts = {
  zoom: 9,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
 };
 var map = new google.maps.Map(document.getElementById("map"), opts);
}

</script>
<head>
<body onload="init();">
<h3>Map</h3>
<div id="map"></div>
</body>
</html>

Does anybody please know, how to center the div in IE as well? Alex

解决方案

Use a doctype, <!DOCTYPE HTML> before anything to trigger standards mode.

这篇关于div在Firefox中居中显示,但不在IE中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆