Given this code:
header {
text-align: center;
}
/* no necessary, only using it to simulate a big table */
p.text {
width: 20rem;
height: 50rem;
}
<html>
<body>
<header>
<h1>Page Title</h1>
<details>
<summary>Click Me</summary>
<p>More information</p>
<p>Even more stuff</p>
</details>
</header>
<table>
<tr>
<td><p class="text">Lorem</p></td>
<td><p class="text">ipsum</p></td>
<td><p class="text">dolors</p></td>
<td><p class="text">itamet</p></td>
<td><p class="text">consectetura</p></td>
<td><p class="text">dipiscinge</p></td>
<td><p class="text">litsed</p></td>
<td><p class="text">doeiusmod</p></td>
</tr>
<tr>
<td><p class="text">Lorem</p></td>
<td><p class="text">ipsum</p></td>
<td><p class="text">dolors</p></td>
<td><p class="text">itamet</p></td>
<td><p class="text">consectetura</p></td>
<td><p class="text">dipiscinge</p></td>
<td><p class="text">litsed</p></td>
<td><p class="text">doeiusmod</p></td>
</tr>
</table>
</body>
</html>
I would like the contents of <header>
to stay centered when scrolling horizontally, but scroll out of view when scrolling vertically.
I've tried position: sticky; left: 0;
with several variations of display
, margin
, etc, to no avail. The closest I've gotten it to work is this:
header {
text-align: center;
position: fixed;
top: 0;
left: 0;
width: 100vw;
z-index: -1;
}
table {
margin-top: 7rem;
}
but that breaks when opening the <details>
element and doesn't work at all in Firefox Mobile.
Trying to stick to a "pure", semantic solution. Not against a little Javascript, but would rather not use a framework.
Thanks in advance for your help.