I have a variable width header that must have a background color that is as wide as the text (no wider). The only way I can think of doing this (with no ext
Solved using display: table; on the heading (with margin: 0 auto;).
replace the p tag with center as my markup is
<div id="header">
<center>hello</center>
</div>
and it's CSS is
body{
width:100%;
}
#header{
text-align:center;
}
#header center{
display:inline-block;
background:red;
}
you can give text-align:center;
to the body
as a global arrtibute & give display:inline-block
to your header
div. So,it's center your dynamic width
in center
like this :
CSS:
body{margin:0; padding:0;text-align:center}
p{text-align:left;}
.header{background:red;display:inline-block;}
Check this example http://jsfiddle.net/vpcXS/