javascript - 有没有办法让页面主体像在 WordPress 网站上那样在页面顶部的图像上滑动?

标签 javascript jquery html css

这是我的代码。这是我的 HTML。我希望页眉中有一个图像背景和滑过页眉的部分。

<body>
    <header id=slideover>
       <div> Hello World</div>
    </header>
    <section>
        <div> stuff</div>
        <div> stuff</div>
        <div> stuff</div>
    </section>
</body>

最佳答案

这是您可以实现的一种方法:使用带有 position:fixed 的固定高度 header 和等于 header 高度的 margin-top 部分:

html, body {
  margin: 0;
}

header {
  position: fixed;
  height: 80px;
  background: url(https://images.pexels.com/photos/111091/pexels-photo-111091.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb) no-repeat center;
  color: white;
  width: 100%;
  top: 0;
  line-height: 80px;
  padding: 0 16px;
  box-sizing: border-box;
}
section {
  margin-top: 80px;
  background: #fff;
  position: relative;
  width: 100%;
  padding: 16px;
  box-sizing: border-box;
}
<body>
    <header id=slideover>
       <div> Hello World</div>
    </header>
    <section>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
          <div> stuff</div>
    </section>
</body>

关于javascript - 有没有办法让页面主体像在 WordPress 网站上那样在页面顶部的图像上滑动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45851888/

相关文章:

javascript - 检测嵌套元素外部的鼠标双击?

javascript - jQuery 循环复选框

javascript - JQuery 切换按钮打开或删除功能

Javascript 将innerHTML发送到服务器ASP.NET

javascript - Ext js 4.2 数据字段转换覆盖不起作用

javascript - Js中 "hasOwnProperty"和 "__proto__"怎么理解?

javascript - 有什么方法可以增加 HTML 所需验证消息的显示时间吗?

html - <dt><dd> 标签行间距

javascript - 下拉选项从其他下拉菜单中删除

jQuery动画问题