How to create div content after a fixed div header with dynamic height
following situation:
<body> <div style="position:fixed; width:100%">[place holder for header]</div> <div style="position:relative;width:100%;margin-top:100px">[content]</div> </body>
I need the title to always be visible at the top, so it should be with the position: fixed. The problem occurs after self-adjusting the height of the header. If the title is above 100 pixels, some of the content is hidden.
How can I (CSS) dynamically set the start position of the contents of a div relative to the end of the header.
I'm still looking for a CSS-only solution, but for now, the idea is using only one line of JavaScript - when using jQuery:
Javascript
$(document).ready(function () { $('#content').css('marginTop', $('#header').outerHeight(true) ); });
HTML
<body> <div id="header" style="[…]">[place holder for header]</div> <div id="content" style="[…]">[content]</div> </body>
The advantage of using .outerHeight(true)
is that it takes care of the borders and marks that you could apply to your header.