Grow your CSS skills. Land your dream job.

style TEXT within P, not paragraph element itself

  • # October 10, 2012 at 12:56 pm

    im styling text in a twitter widget so i dont have control of the markup, just the css. i was hoping to give the text within a `

    ` (that is within a div class) a background color on the text but not have the background color run across the entire paragraph element, just behind the text like a highlight . I normally would throw a span in there, but was hoping i could achieve this with just css. any ideas?

    # October 10, 2012 at 1:05 pm

    Basically I don’t think you can target content within a ‘final’ element.

    The ‘p’, yes, but other than that, I don’t think so.

    Maybe you can target ‘whitespace’ but I’ve never heard of it being done.

    # October 10, 2012 at 1:08 pm

    You can’t do this. The regular way is to use a span. It’s meant to.

    With some pseudo-selectors like :first-line, you can partially select some of the content, but not as you wish.

    If your text is purely static, use a background image on the p element.

    # October 10, 2012 at 1:46 pm

    What happens with you type the tag in you're tweet?
    Like if you tweeted "Today I went to the

    # October 10, 2012 at 4:05 pm

    Yes.

    # October 11, 2012 at 9:26 am

    Oh how I wish we had :nth-line(n) But we don’t, at least for now.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".