CSS Fixed header of unknown height

2019-02-28 14:28发布

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>

标签: html css layout
2条回答
戒情不戒烟
2楼-- · 2019-02-28 15:18

...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.

查看更多
Melony?
3楼-- · 2019-02-28 15:19

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.

查看更多
登录 后发表回答