我试图将我的谷歌地图居中,但它不想从左对齐状态移动。每当我尝试更改它时,它都会删除我的标题。
我的CSS代码
#mapCanvas {
width: 960px;
height: 150px;
margin-left: auto;
margin-right: auto;
}
header {
width: 960px;
height: 150px;
margin-left: auto;
margin-right: auto;
background-color: #339966;
font-family: Garamond;
font-weight: bold;
font-style: italic;
}
h1{
color: white;
font-family: Garamond;
font-weight: normal;
font-style: italic;
text-align: center;
font-size: 40px
}
p {
color: white;
font-family: Garamond;
font-weight: normal;
font-style: italic;
text-align: center;
font-size: 20px;
}
我的代码在我的 html 中
<body>
<header>
<h1>
Find a user's location using HTML5 Geolocation
</h1>
<p> If Geolocation sercive is failed, the University of Maryland Campus will be displayed on a map</p>
</header>
<div id="mapCanvas">
</div>
</body>
[1]: /image/6WZiy.jpg [我目前的成绩][1]
最佳答案
将 position: relative
添加到 #mapCanvas
的规则中,以便左/右自动边距居中。
关于javascript - 在网页中心的标题 block 下居中谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43194836/