div#thing {
position: absolute;
top: 0px;
z-index: 2;
margin: 0 auto;
}
text text text with no fixed size, variable fon
.contentBlock {
width: {define width}
width: 400px;
position: absolute;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
Yes:
div#thing { text-align:center; }
div#thing
{
position: absolute;
width:400px;
right: 0;
left: 0;
margin: auto;
}
I was having the same issue, and my limitation was that i cannot have a predefined width. If your element does not have a fixed width, then try this
div#thing
{
position: absolute;
top: 0px;
z-index: 2;
left:0;
right:0;
}
div#thing-body
{
text-align:center;
}
then modify your html to look like this
<div id="thing">
<div id="thing-child">
<p>text text text with no fixed size, variable font</p>
</div>
</div>
To center it both vertically and horizontally do this:
div#thing {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
Your problem may be solved if you give your div
a fixed width, as follows:
div#thing {
position: absolute;
top: 0px;
z-index: 2;
width:400px;
margin-left:-200px;
left:50%;
}