Reputation: 35720
I have this html:
<div>
<p class="highlight-date">2009-4-5</p>
</dvi>
and here is the css:
div{
width: 200px;
}
div p{
text-align: right;
}
.highlight-date{
background-color: yellow;
}
I'd like to have the background color to be just under the text, but now it would extend from the left of the div. How could I fix this? thanks
Fiddle: http://jsfiddle.net/f6exa/
Upvotes: 0
Views: 1561
Reputation: 41
<div>
<span class="highlight-date">2009-4-5</span>
</div>
<style type="text/css">
div
{
width: 200px;
text-align: right;
}
.highlight-date
{
background-color: yellow;
}
</style>
Upvotes: 1
Reputation: 102753
Here's how you can fix it: http://jsfiddle.net/f6exa/1/
div {
width: 200px;
text-align: right;
}
.highlight-date{
background-color: yellow;
display: inline-block;
}
Changes:
text-align: right
from the content (p) to the container (div).display: inline-block
.Upvotes: 4