For an image gallery I'm designing, I am trying to set the background color of variable-length strings contained inside <p> tags. Setting the background color of <p> is not the problem, the problem is I have been unable to have the color extend to only the length of the string, not to the length of the paragraph tag.
That is, if I have a string 50 pixels wide contained within a paragraph tag contained within a block that is 150 pixels wide, the background color stretches the full 150 pixels instead of limiting itself to only the 50 pixels of text.
Now, my understanding is the width of a paragraph is determined by the width of its containing element. I am also under the (perhaps incorrect?) impression that by setting the width of a container element to "auto" will make the width of the container equal to the width of whatever it contains.
One partially successful solution was to use the span tag...
Code:
<p><span class="black">the background is black here</span</p>
...which gave me the black background I sought but, unfortunately, when used with the JavaScript that controls the display of images and captions on my page, that approach fails. Modifying that code to...
Code:
<p><span class="black" id="desc">placeholder</span></p>
...lets the JavaScript run and sets the background to black, but unfortunately it extends only to the width of the word "placeholder" instead of expanding for wide strings and shrinking for short ones.
What I am working with can be found here...
http://www.diagram32.com/example/example.html
...where I am trying to get the text beneath the image to display in a black bar with 10 pixels of of padding on both ends and 4 pixels on the top and bottom. The span class for that block is...
Code:
span.black
{
background: black;
color: #ffffff;
padding: 4px 10px 4px 10px;
}
Anyone care to take a crack at helping me figure out how to get this to work?
Regards,
G.