[英]How to push page down and append a div at top?
What is the best way to push page down 30px
, and put a div
tag height 30px
at top, like a toolbar? 什么是将页面下推
30px
并将div
标签高度设置为30px
的最佳方法,例如工具栏?
I tried code as below, but it could not push down page that content div with position:absolute;
我尝试了如下代码,但是它无法将具有
position:absolute;
内容div的页面下推 and top:0;
和
top:0;
, or div
with position:fixed;
,或带有
position:fixed;
div
position:fixed;
, z-index:9999;
,
z-index:9999;
top:0;
var divToolbar = document.createElement("div");
divToolbar.id = "divToolbar";
divToolbar.style.width = 100 + "%";
divToolbar.style.height = 30 + "px";
document.body.insertBefore(divToolbar,document.body.firstChild);
If the content div has position:absolute;
如果内容div具有
position:absolute;
it's layout will not be affected by other elements. 它的布局不会受到其他元素的影响。
You would need to add top: 30px
to the content div. 您需要在内容div中添加
top: 30px
。
Use the css below for your content div: 将以下CSS用于您的内容div:
.content {
position:absolute;
top:30px;
}
As the commenter to your post suggested, this seems to be the best option. 正如您的帖子的评论者所建议的那样,这似乎是最好的选择。
.header{
position:fixed;
height:30px;
}
.content{
margin-top:35px;/* or adjust it the way you want */
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.