When I specify text-align:center
for an element with a width that is greater than the width of the text, the text is centered within the content box of the elem
Div magic to the rescue. In case anyone is interested, you can see the solution here.
HTML:
some text
some text that will overflow
CSS:
#outer {
display: block;
position: relative;
left: 100px;
width: 100px;
border: 1px solid black;
background-color: silver;
}
#inner {
/* shrink-to-fit width */
display: inline-block;
position: relative;
/* shift left edge of text to center */
left: 50%;
}
#text {
/* shift left edge of text half distance to left */
margin-left: -50%;
/* text should all be on one line */
white-space: nowrap;
}