我有一个 <div>
它穿过页面并且它的位置固定在顶部。我希望它像横幅一样,其余的 <body>
出现在这个横幅下面,但是因为它的位置:(是)固定的,横幅覆盖了一些其余的内容。
//This is the CSS
#banner {
height: 127px;
width: 100%;
position: fixed;
top: 0;
}
在下面的 html 中,您可以看到 <p>
标签,这会被横幅覆盖,我知道我可以使用 margin-top 来解决这个问题,但是有没有办法让标签真正识别 <div>
的存在?并让路给它?
//This is the html, you can guess what it is...
<div id="banner"></div>
<p>Hello world</p>
提前致谢,P.S:我已经尝试过 clear: both;在 CSS 中 - 仍然不起作用。
最佳答案
只需在正文中添加padding-top
* {
margin: 0;
padding: 0;
}
body {
padding-top: 127px;
}
#banner {
height: 127px;
width: 100%;
position: fixed;
top: 0;
background: red;
}
<div id="banner"></div>
<p>Hello world</p>
关于html - 如何让 FIXED <div> 仍然被其他标签识别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31222510/