http://jsfiddle.net/7U688/
Crafting text alignment is a piece of cake.
The real challenge lies in extending the background in one direction.
One approach to achieving this is outlined below:
#outer{
border:2px solid black;
background-color:red;
overflow:hidden;
}
#inner{
margin:40px;
text-align:center;
}
p{
display:inline-block;
color:white;
background-color:black; // or an image
margin:0 -999em 0 5px;
padding: 5px 999em 5px 5px;
line-height:1;
}
In this scenario, a large padding and negative margin are utilized to visually extend an element beyond its borders while maintaining its flow within the layout. This technique offers the advantage of keeping the element in a standard static or relative position.
Finally, remember to add overflow:hidden
to a parent element to prevent any undesired bleeding effects.