I have a header div and a content div. The content div is wider than the window, so horizontal scrollbar appears, which is fine. I want the header div to occupy the full width, meaning it should stretch to the same width as the content div below it. By default divs are only wide as the window.
What is the simplest way to accomplish this? Can I do it without using JavaScript or tables? I would be fine using flex layout if that helps.
In the example below I want the red div to be the same width as the green div. Currently the red div stops at the edge of the window.
Note that in real code the content width is determined by the child elements I add to it, not set in CSS. This means I can't just set the width of the header div in CSS to match the width of the content div.
Additional clarification: When scrolling horizontally the header and content must scroll together, because header shows headings for the content below. When scrolling vertically the header stays in place (by using position sticky) while content scrolls.
<html>
<head>
<style>
body {
margin: 0;
}
.header {
background-color: red;
height: 50px;
}
.content {
width: 10000px;
height: 250px;
background-color: blue;
}
</style>
</head>
<body>
<div class="header"></div>
<div class="content"></div>
</body>
</html>