如何重叠两个div

4
我正在设计一个新的网站,遇到了一个问题。我希望我的导航栏能够与头部(标志栏)融为一体。
以下是当前的代码效果: enter image description here 以下是我想要实现的效果: enter image description here 目前这是我的CSS代码:
#header {
margin: 0px auto;
width: 900px;
height: 170px;
background: #000;
}

#navigation {
margin: 0px auto;
width: 920px;
height: 60px;
background: url('images/nav.png');
}

我的HTML代码:

        <div id="header">

        </div>


        <div id="navigation">

        </div>
4个回答

6

你可以像这样编写:

#header {
margin: 0 auto;
margin-bottom:-30px;
width: 900px;
height: 170px;
background: #000;
}

2
一个负的 margin 或者 position: absolute 可以解决你的问题。

2

元素通常会有默认的内边距和外边距,这意味着你需要使用负边距来覆盖它(就像第一个答案所示),或者指定margin:0; padding:0;,或者使用CSS重置来避免这种麻烦...


2
添加以下内容:- margin-top ; -30px;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接