我有一个标题,它使用 position:fixed
来保持在页面顶部,它以 50px 高开始,但是,如果添加了更大/更小的 Logo ,它的高度会发生变化,这意味着它可以然后重叠它下面的 DIV 容器。有没有办法根据标题的高度移动 DIV 容器。这是我正在使用的 CSS;
<style>
#header {
position:fixed;
top:0px;
height:50px;
width:100%;
}
.container {
margin-top: 50px;
width: 100%;
height: 250px;
}
</style>
这是我正在使用的 HTML,它非常基础。
<div id="header">
... Menu ...
</div>
<div class="container">
... Content ...
</div>
我研究过使用 javascript,但我知道这是客户端,所以无济于事。有解决办法吗?
最佳答案
您可以使用 jquery 读取容器的高度,然后使用它来设置容器顶部边距的值。
试试这段代码:
$(document).ready(function(){
var h=$("#header").css("height");
$(".container").css("margin-top",h);
});
关于php - 调整 DIV 在固定标题 PHP 下的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36664857/