tags:

views:

88

answers:

3

This is my code:

<div><p><span>... highlighted text ...</span></p><p>Chapter info</p></div>

This is what it currently looks like:

http://i48.tinypic.com/2dqvo1i.png

Is there a way to add padding to the sides of the highlighted text? Regular padding on the SPAN doesn't work, because it only takes into account the the beginning and end of the sentence, not every line separately.

Any ideas? CSS3 code is fine.

+1  A: 

Just pad the "p" tags that surround the spans. The "p" tag (unlike span) is a block-level element, so padding on the top, bottom, or sides will work as expected.

Peter Anselmo
I want to pad the yellow strips of texts, so the text isn't so close to side. Example mock-up: http://i50.tinypic.com/206dlef.pngWhen adding the padding to the P, it just adds padding to the block as whole. However, I want to add the padding to the lines of text individually.I'm starting to think it's not possible, because the line of text is already interpreted as ONE element, but for my idea to work, it needs to interpret each line of text separately for the horizontal padding to work.
Marc
Unfortunately though, I CAN'T create separate elements for each line, because they are created dynamically and I don't know the 'break-off' point beforehand.Ideally there would be an :each-line pseudo-selector, that I could use to pad each line individually.
Marc
A: 

Try inline-block. It won't work in anything older than IE8 (though there are some work arounds), but everything else popular should be fine:

p span {
    display: inline-block;
    padding: 0 2em;
}
robertc
Unfortunately that doesn't work either. It just creates a block element, that doesn't clear it's siblings. Effectively, this means I get a block of yellow, instead of lines of yellow.
Marc
Oh I see. Then I think what you want is not possible - padding by its nature applies to blocks. Some kind of jQuery solution to add non-breaking spaces at appropriate places is the only way to go.
robertc
Too bad. I guess I'll just leave it as is then. Thanks for the help though.
Marc
@Marc It'll not be much use to you, but I've found out today there was a CSS property proposed which would allow you to do this, unfortunately it has since been dropped: http://www.w3.org/TR/2008/WD-css3-background-20080910/#the-border-break
robertc
Interesting to know nevertheless!
Marc