I have a page of fixed width. I don't want to change the width. I want to centre some text on the page so that it is at the centre of the entire page.
Say, if the page width is 4000px and the screen width is 1920px, using text-align: center; puts the text at the centre of the visible part, that is, centred at 960. I can force it using the page width, but I want to make it so that the text is at the centre of the full width, even when I change the width.
So, if the width is 6000px, I want the text centred at 3000px. If it is 1000px, I want the text centred at 500px. And all the while, the screen size remains the same.
In addition, how do I accomplish this for a container that contains text that should be justified, but the container itself should be centred.
A reproducible example as requested:
#mainhead {
background-color: pink;
font-size: 50px;
font-weight: 1000;
color: #e0f2f1;
text-align: center;
}
The page width in this example is set to 4000px due to other stuff. But the heading is always centred at 960px from left, rather than 2000px from the left.