On a WordPress site, in a blog post, I’m attempting to achieve this effect of having a colored rectangle just to the left of an image’s caption:
I’ve tried this, but it puts the rectangle vertically spanning the entire caption. In other words, when the text wraps down one or more lines, the rectangle continues spanning the text downward. In my case, I only want the rectangle to appear next to the first line of the wrapping text.
Here’s all I have right now.
div.wp-caption p.wp-caption-text {
border-top: 40px solid;
padding-left: 12px;
border-color: #008ed4;
}
2
Answers
I would suggest using the
:before
selector and trying something like this:Using the css :before selector and giving it a
content: '';
allows you to essentially fake adding an item to the dom using css.I’m not sure if this is exactly what you want, but I think it will be enough to get you started.
You could indent the first line of the caption and put in a background image (a linear-gradient) that goes in that indent.
This means the caption will wrap under the blue rectangle and I’m not absolutely sure whether that is what you want or not (if not then @BrettEast suggestion of a pseudo element looks promising).