javascript - 在网页中心的标题 block 下居中谷歌地图

标签 javascript css html aptana

我试图将我的谷歌地图居中,但它不想从左对齐状态移动。每当我尝试更改它时,它都会删除我的标题。

我的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/

相关文章:

css - 使用 css 按 % 或最大值填充

css - SVG:我可以在样式的属性中放置 x 和 y 位置吗?

javascript - 识别网页上 AppleScript 的 JavaScript 按钮

javascript - jQuery .size() 函数不适用于变量

javascript - 自动垂直滚动div内容循环

JavaScript .match 函数

javascript - 在响应式网站上无法将高度缩放到宽度

javascript - 开始在文本框中输入时的 Jquery 文本

javascript - 防止输入类型受到 XSS 攻击

html - CSS Transition 不适用于嵌套元素