position fixed header in html

前端 未结 6 1499
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 01:51

I have a header (dynamic height) with a fixed position.

I need to place the container div right below the header. As the header height is dynamic, I can\'t use the

6条回答
  •  [愿得一人]
    2020-12-01 02:41

    Well! As I saw my question now, I realized that I didn't want to mention fixed margin value because of the dynamic height of header.

    Here is what I have been using for such scenarios.

    Calculate the header height using jQuery and apply that as a top margin value.

    var divHeight = $('#header-wrap').height(); 
    $('#container').css('margin-top', divHeight+'px');
    

    Demo

提交回复
热议问题