• I’m trying to find a way to style p in css without affecting images. Images are also within the p. Is there any way I can do that? How can I style the text only?

Viewing 3 replies - 1 through 3 (of 3 total)
  • What attributes are you giving the text in a paragraph that are also effecting images in the paragraph? Do you have a screenshot or example link?

    Thread Starter drhur

    (@drhur)

    I put margins to left and right in order to have less wide text. This made the images less wide too. I solved it by styling the images to undo the effects. But this has caused some problems to images that have different sizes and alignments. So if it is possible to just style the text I would be happy to know how.

    I see. I don’t know of a way to only style the text without a separate element for the CSS to “grab on” to. For example if you wrap all the text in a span you could then target it with CSS.

    However, it might be better to simply keep the images outside of the paragraphs if that’s an option. That way you can target them separately. If you still need them to be “together” for any reason, you could put a wrapper around them both.

    <div class="wrapper">
      <p></p>
      <img src="" alt="">
      <p></p>
      <img src="" alt="">
    </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to style p but not images within p’ is closed to new replies.