[英]CSS menu top of the page
I am going to start working on a small website for my class, I am trying to do a menu that will be positioned at the top of the page. 我将在班级的一个小网站上开始工作,我试图做一个菜单,该菜单将位于页面顶部。
This is what I have: 这就是我所拥有的:
<style>
#menu
{
background:#CCC;
width:100%;
height:40px;
position:absolute;
margin:0;
z-index: 100;
}
</style>
<div id="menu">
</div>
But for some reason this div is not at the top there's a small space between the top and the div(menu); 但是由于某种原因,该div不在顶部,因此在顶部和div(menu)之间有一个很小的空间; also, on the left side there is a small space, how can I fix this?
另外,在左侧有一个很小的空间,我该如何解决?
Add something like this to the top of your CSS file or <style>
tag: 在CSS文件或
<style>
标签的顶部添加以下内容:
* {
margin: 0;
padding: 0;
}
You can then set paddings and margins later on. 然后,您可以稍后设置填充和边距。
This should fix it... 这应该解决它...
body {
margin:0;
}
If you want the navigation menu to stay at the top when you scroll then use this... 如果您希望滚动时导航菜单位于顶部,请使用此...
#menu {
position:fixed;
top:0;
}
Add this code to eliminate the top margin 添加此代码以消除最高利润
body{
margin: 0;
padding: 0;
}
css 的CSS
body,div{
margin:0px;
padding:0px;
}
If you need your menu to be positioned on the top of the page, this is what you need 如果您需要将菜单放在页面顶部,这就是您需要的
#menu
{
position: absolute;
top : 0px;
}
you made on your code the position absolute, but you missed the top attribute 您在代码上设置了绝对位置,但是错过了top属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.