Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Fixed header of unknown height

Tags:

html

css

layout

I have a header fixed to the top of the page that can wrap creating more height when the page is resized to a smaller width.

How do I make the the page content (#wrapper) always begin at the bottom of the header with CSS only?

<body>
 <header>
  This fixed content will wrap on small devices.
 </header>
 <div id="wrapper">
  This content should always begin immediately below the header.
 </div>
<body>
like image 757
Asa Carter Avatar asked Dec 11 '25 10:12

Asa Carter


2 Answers

As you only want to use CSS, you could just set padding-top on your #wrapper div so it moves the content below the bottom of the header. Then adjust the padding-top size for each screen size in media queries.

like image 175
Alan Dunning Avatar answered Dec 13 '25 00:12

Alan Dunning


...As already stated in the comments above, you have to use a JS solution, unless you are able to know at which resolutions the fixed header's height increases in which case you can use media queries and either use padding-top for the #wrapper element equal to the fixed header's height, or use an empty element with height equal to the header's.

like image 32
scooterlord Avatar answered Dec 13 '25 01:12

scooterlord