treehouse : what would you like to learn today?
Web Design Web Development iOS Development

style TEXT within P, not paragraph element itself

  • 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 <p> (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?

  • 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.

  • 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.

  • What happens with you type the tag in you're tweet? Like if you tweeted "Today I went to the <span market</span.", does it display the tags?

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