html - 从顶部偏移背景图像

标签 html css

我正在尝试偏移用于联系部分的背景图像。我希望背景从该部分顶部开始大约 20 像素,以便某些内容出现在内容上方。

这是我该部分的代码:

<section id="contact">
        <div class="container">
            <div class="row">
                <h3 class="section-header wow fadeInUp" style="display: inline-block;">Contact Us</h3>
            </div>
            <div class="row" style="padding-top: 20px;">
                <!-- <div id="google-map" style="height:300px;" data-latitude="10.943816" data-longitude="76.934372"></div> -->
                <div id="map" style="height:300px;"></div>
                <script>

                </script>
            </div>
        </div>
    </section>

我的该部分的 CSS :

#contact {
    text-align: center;
    padding-bottom: 10px;
    background-image: url('../images/slider/bg1.jpg');
}

我实际上正在尝试实现像 here 这样的联系部分

但我只能做this到目前为止。

请帮助我实现这一目标。

此外,Google map 部分似乎没有响应。请让我知道如何使其具有响应性。

最佳答案

使用background-position来定位图像

在您的情况下,您想将其垂直放置,因此需要使用background-position-y

#contact {
  text-align: center;
  padding-bottom: 10px;
  background-image: url('https://www.w3schools.com/css/img_fjords.jpg');
  background-position-y: 50px;
  background-repeat: no-repeat;
  background-size: 100%;
}
<section id="contact">
  <div class="container">
    <div class="row">
      <h3 class="section-header wow fadeInUp" style="display: inline-block;">Contact Us</h3>
    </div>
    <div class="row" style="padding-top: 20px;">
      <!-- <div id="google-map" style="height:300px;" data-latitude="10.943816" data-longitude="76.934372"></div> -->
      <div id="map" style="height:300px;"></div>
      <script>
      </script>
    </div>
  </div>
</section>

关于html - 从顶部偏移背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43828880/

相关文章:

html - 谷歌地图作为 foursquare 上的固定背景

jquery - Bootstrap Youtube Modal 的按钮无法使用我无法修复的运行时错误进行测试

java - HotSwap Wicket HTML 文件在 Intellij maven + tomcat 中不起作用

javascript - Markerclusterer 根据其中的标记设置标记簇图标

php - Excel 无法打开由 XLSXWriter 创建的文件

jQuery - 维护移动和桌面内容选择选项卡之间的事件类 - 包括 CodePen 链接

javascript - 使用 JavaScript 或 Jquery 链接到过滤后的 html

html - 试图在页面顶部的导航栏上方添加一个 div

html - 对齐两个 flex 元素 : one to the top, 另一个居中

javascript - 在 Firebug 中哪里可以找到 PIE.htc?