I do know the solutions from how to center absolute positioned element in div. But my situation is, instead of a fixed length div, I have a variable length text.
I want the div increase length with text while keep centered. I guess I can use js to programmatically change the width, but that sounds too hacky, is there a pure css solution?
Example: http://jsfiddle.net/tling/3KTUM/307/
.outer_div {
background-color: #999;
border: 0px solid black;
width: 300px;
height: 200px;
float: left;
position: relative;
}
.inner_div {
position: absolute;
background-color: #BBB;
width: 100px;
/*adjustable width with text ?*/
height: 50px;
color: black;
margin: 0 auto;
right: 0;
left: 0;
}
<div class="outer_div">
<div class="inner_div">Text Text Text</div>
</div>