首页 > 解决方案 > 向下移动页面的整个 html 内容?

问题描述

我想使用 javascript 在页面中插入标题。我不想隐藏原始内容中的任何内容,只想在上面添加一个已修复的标题。请记住,我不知道我要操作的页面的内容。

我尝试在 body 元素中添加一个 margin-top:

body{
  margin-top: 40px;
}

但是如果有任何位置固定的元素:

.header{
   position: fixed;
   top: 0;
}

它们将保留在页面顶部。

你有什么建议吗?

标签: javascripthtmlcssheadercss-position

解决方案


尝试

body{
  padding-top: 40px;
}
header {
  position: fixed;
  top: 40px;
}

推荐阅读