简体   繁体   English

调整DIV在固定标头PHP下的位置

[英]Adjust position of DIV beneath fixed header PHP

I have a header that uses position:fixed to stay at the top of the page, it starts as 50px high, however, if a larger/smaller logo is added it's height changes meaning it can then overlap the DIV container beneath it. 我有一个标头,它使用position:fixed停留在页面顶部,起始高度为50px,但是,如果添加了较大/较小的徽标,则其高度会发生变化,这意味着它可以与下面的DIV容器重叠。 Is there a way to move the DIV container based on the height of the header. 有没有一种方法可以根据标题的高度移动DIV容器。 This is the CSS I am using; 这是我正在使用的CSS。

<style>
#header {
position:fixed;
top:0px;
height:50px;
width:100%;
}

.container {
margin-top: 50px;
width: 100%;
height: 250px;
}

</style>

This is the HTML I am using, its really quite basic. 这是我正在使用的HTML,它的确非常基础。

<div id="header">
  ... Menu ...
</div>

<div class="container">
  ... Content ...
</div>

I have looked into using javascript but I understand this is client side so would not help. 我已经研究过使用javascript,但我知道这是客户端,因此无济于事。 Is there a way around this? 有没有解决的办法?

You can use jquery to read the height of the container and then use this to set the value for margin-top of container . 您可以使用jquery读取容器的高度,然后使用它来设置container margin-top的值。

Try this code: 试试这个代码:

$(document).ready(function(){
  var h=$("#header").css("height");
  $(".container").css("margin-top",h);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM